修改系统时间 分为System Clock(系统时间)和Real Time Clock (硬件时间,简称RTC)
使用root用户查看系统时间 #date
查看硬件时间# hwclock --show
更新系统年月日# timedatectl set-time 2017-06-13
更新系统时分秒# timedatectl set-time 10:25:17
将硬件时钟调整为与系统时钟一致 timedatectl set-local-rtc 1
或者# hwclock --systohc --localtime
将日期写入CMOS clock –w
修改时区:(将Asia/shanghai-上海时区写入当前时区)#cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
提示是否覆盖,输入Y回车,
新建数据库修正编码方式(主库和备库同时需要)
CREATE DATABASE fintest
WITH
OWNER = postgres
ENCODING = 'UTF8'
LC_COLLATE = 'en_US.utf8'
LC_CTYPE = 'en_US.utf8'
TABLESPACE = pg_default
TEMPLATE = template0
CONNECTION LIMIT = -1;
从源数据库导出测试数据
pg_dump -h 127.0.0.1 -t dt_user -t dt_dep -t dt_dev -t st_device -t fin_crowd_detail -t fin_crowd_master -t fin_rule_acdep -t fin_rule_master -t fin_device -t fin_card -t fin_account -t fin_sub_account -t fin_device_control -t fin_device_flow -t fin_trad_type -t fin_day_total -t fin_meal_total -t fin_merchant_account -t fin_tt_trad_type -t fin_tt_event_lend -a fintest --inserts >/var/lib/pgsql/fin_pg_20180206.sql
或者
pg_dump -h 127.0.0.1 -t dt_user -t dt_dep -t dt_dev -t st_device -t fin_crowd_detail -t fin_crowd_master -t fin_rule_acdep -t fin_rule_master -t fin_device -t fin_card -t fin_account -t fin_sub_account -t fin_device_control -t fin_device_flow -t fin_trad_type -t fin_day_total -t fin_meal_total -t fin_merchant_account -t fin_tt_trad_type -t fin_tt_event_lend -a fintest >/var/lib/pgsql/fin_pg_20180206.sql
pg_dump -h 127.0.0.1 -t app_account_role -t app_account_info -a postgres >/var/lib/pg_account_app_20180207.sql
pg_dump -h 127.0.0.1 -t basic_account_info -a postgres >/var/lib/pg_account_basic_20180207.sql
pg_dump -h localhost acc_data >/var/lib/account_all_20180207.sql
导入到目标数据库(主库和备库同时需要)
导入基础数据库(主库和备库同时需要)
psql -h localhost -d fintest -U postgres -f /var/fin_pg20180201.sql
psql -h localhost -d acc_data -U postgres -f /var/lib/pg_account_app_20180207.sql
psql -h localhost -d acc_data -U postgres -f /var/lib/pg_account_basic_20180207.sql
测试数据导入表统计(主库和备库同时需要)
drop table if exists insert_table;
create table insert_table (id serial,tablename varchar(100),flg int default 0);
insert into insert_table(tablename)
values ('dt_user'),('dt_dep'),('dt_dev'),('st_device'),('fin_crowd_detail'),('fin_crowd_master'),('fin_rule_acdep'),('fin_rule_master'),('fin_device'),('fin_card'),('fin_account'),('fin_sub_account'),('fin_device_control'),('fin_device_flow'),('fin_day_total'),('fin_meal_total'),('fin_merchant_account'),
('fin_tt_trad_type'), ('fin_tt_event_lend');
测试数据导入错误删除数据(主库和备库同时需要)
CREATE OR REPLACE FUNCTION public.cursor_demo(
)
RETURNS refcursor
LANGUAGE 'plpgsql'
COST 100.0
AS $function$
declare
unbound_refcursor refcursor;
t_accid varchar(100);
sql text;
begin
open unbound_refcursor for execute 'select tablename from insert_table';
loop
fetch unbound_refcursor into t_accid;
if found then
sql := 'truncate table ' || t_accid;
EXECUTE sql;
raise notice '%',sql;
else
exit;
end if;
end loop;
close unbound_refcursor;
raise notice 'the end of msg...';
return unbound_refcursor;
exception when others then
raise exception 'error-----(%)',sqlerrm;
end;
$function$;
ALTER FUNCTION public.cursor_demo()
OWNER TO postgres;
select cursor_demo();
导入测试数据库(主库和备库同时需要)
psql -h localhost -d fintest -U postgres -f /var/fin_Pg_20180206.sql
导入数据fin_bill_date(主库和备库同时需要)
insert into fin_bill_date(id,current_day,next_day,off_set)
values (1,'2017-12-11','2017-12-12',120);
重置序列值(主库和备库同时需要)
select max(xh) from dt_card;
alter sequence dt_card_xh_seq restart 12345 ;
-- dt_card_xh_seq;
dt_dev_xh_seq;
fin_crowd_master_crowd_id_seq;
fin_rule_acdep_id_seq;
fin_rule_master_id_seq;
fin_sub_account_sub_id_seq;
fin_day_total_id_seq;
fin_meal_total_id_seq;
fin_tt_event_lend_id_seq;
验证数据正确性
select * from pg_tables a ,pg_class b where a.tablename =b.relname and reltuples >0 AND a.schemaname ='public';
drop table if exists pg_tables_public;
create table pg_tables_public as
select * from pg_tables a where a.schemaname ='public';
create table pg_tables_public_reltupes as
select * from pg_tables a ,pg_class b where a.tablename =b.relname and reltuples >0 AND a.schemaname ='public';
select tablename from pg_tables_public_reltupes;
SELECT relname, reltuples from pg_tables a ,pg_class b
WHERE a.tablename= b.relname and tablename NOT LIKE 'pg%' AND tablename NOT LIKE 'sql_%' and reltuples>0
ORDER BY tablename ;
配置pglogical
添加主键(主库和备库同时需要)
alter table fin_device_control add primary key (device_id);
alter table fin_log_history add primary key (id);
alter table fin_merchant_device add column id int primary key ;
alter table fin_sub_expired add column id int primary key ;
alter table fin_identity_type add primary key (id);
alter table fin_tt_cred add primary key (cred_id);
alter table fin_tt_key add column id int ;
update fin_tt_key set id =1;
alter table fin_tt_key add primary key (id);
插入表格到默认集(仅仅主库需要)
select pglogical.replication_set_add_table('default','fin_account');
select pglogical.replication_set_add_table('default','fin_account_card_synch');
select pglogical.replication_set_add_table('default','fin_account_unit');
select pglogical.replication_set_add_table('default','fin_acdep_dev');
select pglogical.replication_set_add_table('default','fin_acdep_mode');
select pglogical.replication_set_add_table('default','fin_bank_trans_flow');
select pglogical.replication_set_add_table('default','fin_card');
select pglogical.replication_set_add_table('default','fin_card_cardslot');
select pglogical.replication_set_add_table('default','fin_card_dynamic');
select pglogical.replication_set_add_table('default','fin_crowd_detail');
select pglogical.replication_set_add_table('default','fin_crowd_master');
select pglogical.replication_set_add_table('default','fin_crowd_rule');
select pglogical.replication_set_add_table('default','fin_dep_amt');
select pglogical.replication_set_add_table('default','fin_day_total');
select pglogical.replication_set_add_table('default','fin_deposit_set');
select pglogical.replication_set_add_table('default','fin_destroy_account');
select pglogical.replication_set_add_table('default','fin_device');
select pglogical.replication_set_add_table('default','fin_device_control');
select pglogical.replication_set_add_table('default','fin_device_dynamic');
select pglogical.replication_set_add_table('default','fin_device_flow');
select pglogical.replication_set_add_table('default','fin_fee_set');
select pglogical.replication_set_add_table('default','fin_global_authorization');
select pglogical.replication_set_add_table('default','fin_identity_set');
select pglogical.replication_set_add_table('default','fin_log');
select pglogical.replication_set_add_table('default','fin_log_history');
select pglogical.replication_set_add_table('default','fin_meal');
select pglogical.replication_set_add_table('default','fin_meal_total');
select pglogical.replication_set_add_table('default','fin_merchant_account');
select pglogical.replication_set_add_table('default','fin_merchant_dep');
select pglogical.replication_set_add_table('default','fin_merchant_device');
select pglogical.replication_set_add_table('default','fin_merchant_power');
select pglogical.replication_set_add_table('default','fin_offline_error_record');
select pglogical.replication_set_add_table('default','fin_open_account');
select pglogical.replication_set_add_table('default','fin_operator_ip');
select pglogical.replication_set_add_table('default','fin_pos_real_total');
select pglogical.replication_set_add_table('default','fin_rule_acdep');
select pglogical.replication_set_add_table('default','fin_rule_master');
select pglogical.replication_set_add_table('default','fin_sub_account');
select pglogical.replication_set_add_table('default','fin_sub_expired');
select pglogical.replication_set_add_table('default','fin_sub_flow');
select pglogical.replication_set_add_table('default','fin_sub_import_result');
select pglogical.replication_set_add_table('default','fin_sub_master');
select pglogical.replication_set_add_table('default','fin_sub_slave');
select pglogical.replication_set_add_table('default','fin_subject_amt');
select pglogical.replication_set_add_table('default','fin_subject_amt_bak');
select pglogical.replication_set_add_table('default','fin_system_set');
select pglogical.replication_set_add_table('default','fin_trans_log');
select pglogical.replication_set_add_table('default','fin_tt_card_type');
select pglogical.replication_set_add_table('default','fin_tt_cardholder_payment');
select pglogical.replication_set_add_table('default','fin_tt_cardreader');
select pglogical.replication_set_add_table('default','fin_tt_cardslot');
select pglogical.replication_set_add_table('default','fin_tt_cred');
select pglogical.replication_set_add_table('default','fin_tt_event_lend');
更新统计信息
analyse;
查看是否插入
insert into fin_system_set(sys_name,current_day,next_day,is_auto_bill,auto_bill_time,sys_state,month_start_date,fixed_setting,sys_account,sys_card_serial,sys_merchant,operator,client,sj,off_set,time_out)
values('在线消费系统',cast('2017-12-01' as date),cast('2017-12-02' as date),1,'00:00',1,10,30,1,1,1,'sys','127.0.0.1',now(),120,300);