mkdir -p /var/lib/pgsql/16/recoverychown postgres /var/lib/pgsql/16/recovery
/var/lib/pgsql/12
for PostgreSQL 12.x./var/lib/pgsql/16/recovery
directory./var/lib/pgsql/16/recovery
directory in the CVM after the download. For more information, see Copying Local Files to CVMs.[postgres@VM-0-5-tencentos recovery]$ ls -lhtotal 9.1M-rw-r--r-- 1 postgres postgres 9.1M Aug 5 12:40 pgsql_1026780_data_2024-08-05_automatic-20240805015133.tar.zst
cd /var/lib/pgsql/16/recoverytar -I zstd -xvf pgsql_1026780_data_2024-08-05_automatic-20240805015133.tar.zst
[postgres@VM-0-5-tencentos recovery]$ ls -lhtotal 9.2M-rw------- 1 postgres postgres 225 Aug 5 01:51 backup_label-rw------- 1 postgres postgres 225 Jul 30 20:36 backup_label.olddrwx------ 6 postgres postgres 4.0K Aug 5 12:45 base-rw------- 1 postgres postgres 56 Aug 5 01:00 current_audit_logfiles-rw------- 1 postgres postgres 35 Aug 5 00:00 current_logfilesdrwx------ 2 postgres postgres 4.0K Aug 5 12:45 globaldrwx------ 2 postgres postgres 4.0K Jul 30 20:36 pg_commit_tsdrwx------ 2 postgres postgres 4.0K Jul 30 20:36 pg_dynshmem-rw------- 1 postgres postgres 308 Jul 30 20:36 pg_hba.conf-rw------- 1 postgres postgres 2.6K Jul 30 20:36 pg_ident.confdrwx------ 4 postgres postgres 4.0K Jul 31 10:19 pg_logicaldrwx------ 4 postgres postgres 4.0K Jul 30 20:36 pg_multixactdrwx------ 2 postgres postgres 4.0K Jul 30 20:36 pg_notifydrwx------ 2 postgres postgres 4.0K Aug 5 01:51 pg_replslotdrwx------ 2 postgres postgres 4.0K Jul 30 20:36 pg_serialdrwx------ 2 postgres postgres 4.0K Jul 30 20:36 pg_snapshots-rw-r--r-- 1 postgres postgres 9.1M Aug 5 12:40 pgsql_1026780_data_2024-08-05_automatic-20240805015133.tar.zstdrwx------ 2 postgres postgres 4.0K Jul 30 20:36 pg_statdrwx------ 2 postgres postgres 4.0K Jul 30 20:36 pg_stat_tmpdrwx------ 2 postgres postgres 4.0K Jul 30 20:54 pg_subtransdrwx------ 2 postgres postgres 4.0K Jul 30 20:36 pg_tblspcdrwx------ 2 postgres postgres 4.0K Jul 30 20:36 pg_twophase-rw------- 1 postgres postgres 3 Jul 30 20:36 PG_VERSIONdrwx------ 3 postgres postgres 4.0K Aug 5 12:45 pg_waldrwx------ 2 postgres postgres 4.0K Jul 30 20:36 pg_xact-rw------- 1 postgres postgres 2.3K Jul 30 20:36 postgresql.conf-rw------- 1 postgres postgres 0 Jul 30 20:36 standby.signal-rw------- 1 postgres postgres 0 Aug 5 01:51 tablespace_map-rw------- 1 postgres postgres 2 Jul 30 20:36 TENCENTDB_RELEASE
rm -rf backup_label
postgresql.conf
.synchronous_standby_namesshared_preload_librarieslocal_preload_librariespg_stat_statements.maxpg_stat_statements.trackarchive_modearchive_commandsynchronous_committencentdb_az_fiveextension_blacklistdisable_dblink_connect_to_othertencentdb_enable_trusted_extensionbasebackup_exclude_pathstencentdb_enable_superuser_unsafe_behavioursoft_limit_connections
include = 'standby.conf'
.postgresql.conf
.port = '5432' ## Change the value of the port parameter to 5432
postgresql.conf
file, indicating that the strong sync mode will no longer be used.synchronous_commit = localsynchronous_standby_names = ''
chmod 0700 /var/lib/pgsql/16/recoverychown postgres:postgres /var/lib/pgsql/16/recovery -R
/var/lib/pgsql/16/recovery/pg_wal
folder. If the downloaded backup does not contain the pg_wal
directory, modify pg_xlog
to pg_wal
, and PostgreSQL will automatically place the xlog files again.pg_wal
folder, then the database can be restored to the data content at 13:00./var/lib/pgsql/9.x/recovery/pg_xlog
.pg_wal
folder.tar -I zstd -xvf pgsql_1026780_xlog_2024-08-05_20240805133238_20240805133241-20240805133241-00000001000000000000000B_00000001000000000000000F.tar.zst
/usr/local/pgsql/bin/pg_ctl start -D /var/lib/pgsql/16/recovery -l logfile
/usr/local/pgsql/bin/pg_ctl status -D /var/lib/pgsql/16/recovery
[postgres@VM-0-5-tencentos recovery]$ /usr/local/pgsql/bin/psql -h127.0.0.1 -p 5432 -Udbadmin -dpostgrespsql (16.0)Type "help" for help.postgres=>
Parameter | Description |
host | The connection address of the TencentDB for PostgreSQL instance. |
port | The port of the TencentDB for PostgreSQL instance. |
username | The account name of the TencentDB for PostgreSQL instance. |
-Fc | Output format, which is suitable for pg_restore for restoration. |
dbname | The name of the database to be exported. |
dumpdir | The path and name of the exported backup file. |
pg_dump -h 10.0.13.13 -p 5432 -U dbadmin -Fc testdb > testdb_bkp.dump
Password:
, enter the access account password, and the file will be successfully exported. You can run ll testdb_bkp.dump
to ensure the file is generated.[postgres@VM-0-14-tencentos root]$ psql -h127.0.0.1 -p5432 -Upostgres -dpostgrespsql (16.0)Type "help" for help.postgres=# \duList of rolesRole name | Attributes-----------+------------------------------------------------------------postgres | Superuser, Create role, Create DB, Replication, Bypass RLSpostgres=# CREATE USER dbadmin WITH PASSWORD '123456' SUPERUSER;CREATE ROLEpostgres=# \duList of rolesRole name | Attributes-----------+------------------------------------------------------------dbadmin | Superuserpostgres | Superuser, Create role, Create DB, Replication, Bypass RLSpostgres=#
[postgres@VM-0-14-tencentos root]$ psql -h127.0.0.1 -p5432 -Udbadmin -dpostgrespsql (16.0)Type "help" for help.postgres=# select datname from pg_database;datname-----------template1template0postgres(3 rows)postgres=# create database testdb;CREATE DATABASEpostgres=# select datname from pg_database;datname-----------template1template0postgrestestdb(4 rows)postgres=#
Parameter | Description |
host | The connection address of the self-built PostgreSQL instance. |
port | The port of the self-built PostgreSQL instance. |
username | The account name of the self-built PostgreSQL instance. |
dbname | The name of the database to be imported. |
dumpdir | The path and name of the backup file to be imported. |
-c | -c is an optional parameter, indicating that the relevant data in the target database will be cleared before data restoration. |
pg_restore -h 127.0.0.1 -p 5432 -U dbadmin -d testdb testdb_bkp.dump -c
[postgres@VM-0-14-tencentos root]$ psql -h127.0.0.1 -p5432 -Udbadmin -dpostgrespsql (16.0)Type "help" for help.postgres=# \c testdbYou are now connected to database "testdb" as user "dbadmin".testdb=# SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';table_name------------sbtest1sbtest10sbtest2sbtest3sbtest4sbtest5sbtest6sbtest7sbtest8sbtest9(10 rows)testdb=#