Ubuntu Server Guide
Note Replace the domain name with your actual server domain name. Streaming Replication
Download 1.23 Mb. Pdf ko'rish
|
ubuntu-server-guide (1)
Note
Replace the domain name with your actual server domain name. Streaming Replication PostgreSQL has a nice feature called Streaming Replication which provides the capability to continuously ship and apply the WAL XLOG records to some number of standby servers in order to keep them current. Here is presented a very basic and simple way to replicate a PostgreSQL server (master) in a standby server. First, create a replication user in the master to be used by the standby server: $ sudo −u p o s t g r e s c r e a t e u s e r −−r e p l i c a t i o n −P −e r e p l i c a t o r Let’s configure the master server to turn on the streaming replication. Open the file /etc/postgresql/12/ main/postgresql.conf and make sure you have the following lines: l i s t e n _ a d d r e s s e s = ’ * ’ w a l _ l e v e l = r e p l i c a max_wal_senders = 10 Also edit the file /etc/postgresql/12/main/pg_hba.conf to add an extra line to allow tthe standby server connection using the replicator user: h o s t r e p l i c a t i o n r e p l i c a t o r md5 Restart the service to apply changes: $ sudo s y s t e m c t l r e s t a r t p o s t g r e s q l Now, in the standby server, let’s stop the PostgreSQL service: $ sudo s y s t e m c t l s t o p p o s t g r e s q l Edit the /etc/postgresql/12/main/postgresql.conf to set up hot standby: hot_standby = on Back up the current state of the master server: $ sudo su − p o s t g r e s $ cp −R / var / l i b / p o s t g r e s q l /12/ main / var / l i b / p o s t g r e s q l /12/ main_bak $ rm − r f / var / l i b / p o s t g r e s q l /12/ main /* # remove a l l t h e f i l e s i n t h e data d i r e c t o r y $ pg_basebackup −h U r e p l i c a t o r −P −v −R 135 In the pg_basebackup command the flags represent the following: • −h: the hostname or IP address of the master server • −D: the data directory • −U: the user to be used in the operation • −P: tuns on progess reporting • −v: enables verbose mode • −R: Creates a standby.signal file and append connection settings to postgresql .auto.conf Finally, let’s start the PostgreSQL service on standby server: $ sudo s y s t e m c t l s t a r t p o s t g r e s q l To make sure it is working, go to the master server and run the following command: $ sudo −u p o s t g r e s p s q l −c ” s e l e c t * from p g _ s t a t _ r e p l i c a t i o n ; ” You need to see an entry for the standby server. As you can see in the presented row the data synchronization is assynchronous. If you want to make it synchronous, go to the /etc/postgresql/12/main/postgresql.conf file in the master server and make sure you have the following lines: synchronous_commit = on synchronous_standby_names = ’ * ’ # you can a l s o s p e c i f y a IP a d d r e s s And restart the service: $ sudo s y s t e m c t l r e s t a r t p o s t g r e s q l Now, you can check the pg_stat_replication table again and the sync_state of the standby server need to become sync instead of async: $ sudo −u p o s t g r e s p s q l −c ” s e l e c t * from p g _ s t a t _ r e p l i c a t i o n ; ” To test the replication you can now create a test database in the master and check if it is replicated in the standby server: $ sudo −u p o s t g r e s c r e a t e d b t e s t # on t h e master s e r v e r $ sudo −u p o s t g r e s p s q l −c ”\ l ” # on t h e standby s e r v e r You need to be able to see the test database created on the master in the standby server. Download 1.23 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling