Pg_basebackup will connect to the primary and simply copy all the data files over. D /var/lib/pgsql/13/data/ -R -slot=some_name -C However, it is necessary if you want to turn an existing server into a data]# su postgresīash-4.4$ pg_basebackup -h 10.0.3.200 -U repuser -checkpoint=fast \ Note that this step is not necessary if you have skipped the initdb step during installation. PG_VERSION global pg_dynshmem pg_logical pg_replslot pg_stat pg_tblspc pg_xact postmaster.optsīase log pg_hba.conf pg_multixact pg_serial pg_stat_tmp pg_twophase Ĭurrent_logfiles pg_commit_ts pg_nf pg_notify pg_snapshots pg_subtrans pg_wal data]# rm -rf * Then, we need to make sure the data directory is ~]# cd data]# ls Let’s first make sure the service is stopped: ~]# systemctl stop postgresql-13 The first thing is to make sure that the replica is stopped and that the data directory is empty. There are various things we need to do to make this work. Your system is now ready, and we can focus our attention on the replica. If you only changed pg_hba.conf a reload is ~]$ ~]# systemctl restart postgresql-13 Keep in mind that 10.0.3.200 is the primary in our setup and 10.0.3.201 is the replica.įinally, we can restart the primary because we have changed listen_addresses in nf. We want to allow the repuser coming from 10.0.3.201 to log in and stream the transaction log from the primary. Host replication repuser 10.0.3.201/32 trust Please add the following line to the configuration file: The next thing we can do is to change pg_hba.conf, which controls who is allowed to connect to PostgreSQL from which IP. The basic idea is to avoid using the superuser to stream the transaction log from the primary to the replica. What is important here is that the user has the REPLICATION flag set. Postgres=# CREATE USER repuser REPLICATION Then we can already create the user in the database: Without it, remote access is not possible (even if you change pg_hba.conf later on). In other words: listen_addresses defines the bind addresses of our database service. Therefore, we have to teach PostgreSQL to listen on remote requests as well. Remote access is not allowed by default for security reasons. What does listen_addresses mean? By default, PostgreSQL only listens on localhost. The following parameter has to be changed in nf: Here is how it ~]# su - ~]$ psql postgres However, if you have no clue where to find nf you can ask PostgreSQL itself to point you to the configuration file. The file can be found in /var/lib/pgsql/13/data/nf. We can perform these things step-by-step.
0 Comments
Leave a Reply. |