How to set archive in PostgreSQL DB

 How to set archive in PostgreSQL DB


Check Archive Status

show archive_mode;

Stop PostgreSQL DB

C:\Users\amits>pg_ctl stop -D "D:\Program Files\PostgreSQL\data"
waiting for server to shut down.... done
server stopped

Need to update configuration file

Postgresql.conf

wal_level = replica
archive_mode = on
archive_command = 'copy "%p" "D:\\pg_archive\\%f"'

Start PostgreSQL DB

C:\Users\amits>
C:\Users\amits>pg_ctl start -D "D:\Program Files\PostgreSQL\data"


Switch log to check current status

postgres=# select pg_switch_wal();
 pg_switch_wal
---------------
 0/5E215B0
(1 row)

postgres=# SHOW log_directory;
 log_directory
---------------
 log
(1 row)

postgres=# SELECT  pg_current_logfile();
          pg_current_logfile
--------------------------------------
 log/postgresql-2024-08-02_222520.log


Comments