postgres@pgserver1:~/postgresql-12.3$ initdb The files belonging to this database system will be owned by user "postgres". This user must also own the server process.
The database cluster will be initialized with locales COLLATE: en_US.UTF-8 CTYPE: en_US.UTF-8 MESSAGES: en_US.UTF-8 MONETARY: zh_CN.UTF-8 NUMERIC: zh_CN.UTF-8 TIME: zh_CN.UTF-8 The default database encoding has accordingly been setto"UTF8". The default text search configuration will be setto"english".
Data page checksums are disabled.
creating directory /home/postgres/pg120_data ... ok creating subdirectories ... ok selecting dynamic shared memory implementation ... posix selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting default time zone ... Asia/Shanghai creating configuration files ... ok running bootstrap script ... ok performing post-bootstrap initialization ... ok syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
listen_addresses = '*'# what IP address(es) to listen on; # comma-separated list of addresses; # defaults to 'localhost'; use '*' for all # (change requires restart) port = 5432# (change requires restart)
logging_collector = on# Enable capturing of stderr and csvlog # into log files. Required to be on for # csvlogs. # (change requires restart)
# These are only used if logging_collector is on: log_directory = 'log'# directory where log files are written, # can be absolute or relative to PGDATA log_filename = 'postgresql-%a.log'# log file name pattern, # can include strftime() escapes #log_file_mode = 0600 # creation mode for log files, # begin with 0 to use octal notation log_truncate_on_rotation = on# If on, an existing log file with the # same name as the new log file will be # truncated rather than appended to. # But such truncation only occurs on # time-driven rotation, not on restarts # or size-driven rotation. Default is # off, meaning append to existing files
启动数据库
1 2 3 4 5 6 7 8 9
postgres@pgserver1:~/postgresql-12.3$ pg_ctl start waiting for server to start....2020-08-11 14:39:44.004 CST [3608866] LOG: starting PostgreSQL 12.3 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0, 64-bit 2020-08-11 14:39:44.004 CST [3608866] LOG: listening on IPv4 address "0.0.0.0", port 5432 2020-08-11 14:39:44.004 CST [3608866] LOG: listening on IPv6 address "::", port 5432 2020-08-11 14:39:44.006 CST [3608866] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432" 2020-08-11 14:39:44.012 CST [3608866] LOG: redirecting log output to logging collector process 2020-08-11 14:39:44.012 CST [3608866] HINT: Future log output will appear in directory "log". done server started
主节点创建流复制用户
1 2 3 4 5 6 7 8 9
postgres@pgserver1:~/postgresql-12.3$ psql psql (12.3) Type "help"for help.
postgres=# \! uuidgen 7089bae5-c467-492a-a402-aaba388e6826 postgres=# create user replicator Replication password '7089bae5-c467-492a-a402-aaba388e6826'; CREATE ROLE postgres=#
增加用户replicator ACL
主库 vim $PGDATA/pg_hba.conf 新增, x.x.x.x为从节点IP
1
host replication replicator x.x.x.x/32 trust
使之生效
1 2 3 4 5 6 7 8 9
postgres@pgserver1:~$ psql psql (12.3) Type "help" for help.
postgres=# select pg_reload_conf(); pg_reload_conf ---------------- t (1row)