mkdir -p /var/lib/pgsql/16/recoverychown postgres /var/lib/pgsql/16/recovery
/var/lib/pgsql/12.[root@VM-10-5-tencentos postgresql-16.8]# wget -O /var/lib/pgsql/16/recovery/file_name.tar.zst "https://postgres-backup-gz-******.cos.ap-guangzhou.myqcloud.com/pgsql/1030559/data/20**-**-**/automatic-**********.tar.zst?q-sign-algorithm=sha1&q-ak=AKIDjHZcZJpqnqiL0jP4awHZg6McnqiYIwNZ&q-sign-time=1746776185%3B1746819385&q-key-time=1746776185%3B1746819385&q-header-list=host&q-url-param-list=&q-signature=68309d4bbc1bea30fef07776a2aa9fd699c19aa9"
[root@VM-10-5-tencentos postgresql-16.8]# ls -lh /var/lib/pgsql/16/recoverytotal 3952-rw-r--r-- 1 root root 4045802 May 7 20:42 manual-20250507204222.tar.zst
[root@VM-10-5-tencentos postgresql-16.8]# zstd --version*** zstd command line interface 64-bits v1.4.4, by Yann Collet ***
[root@VM-10-5-tencentos postgresql-16.8]# sudo yum install epel-release[root@VM-10-5-tencentos postgresql-16.8]# sudo yum install zstd
[root@VM-10-5-tencentos postgresql-16.8]# cd /var/lib/pgsql/16/recovery[root@VM-10-5-tencentos recovery]# tar -I zstd -xvf file_name.tar.zst
[root@VM-10-5-tencentos recovery]# ls -lhtotal 4.0M-rw------- 1 postgres postgres 225 May 7 20:42 backup_label-rw------- 1 postgres postgres 225 May 7 20:31 backup_label.olddrwx------ 6 postgres postgres 4.0K May 7 21:13 base-rw------- 1 postgres postgres 56 May 7 20:31 current_audit_logfiles-rw------- 1 postgres postgres 35 May 7 20:31 current_logfilesdrwx------ 2 postgres postgres 4.0K May 7 21:13 global-rw-r--r-- 1 root root 3.9M May 7 20:42 manual-20250507204222.tar.zstdrwx------ 2 postgres postgres 4.0K May 7 20:31 pg_commit_tsdrwx------ 2 postgres postgres 4.0K May 7 20:31 pg_dynshmem-rw------- 1 postgres postgres 308 May 7 20:31 pg_hba.conf-rw------- 1 postgres postgres 2.6K May 7 20:31 pg_ident.confdrwx------ 4 postgres postgres 4.0K May 7 20:31 pg_logicaldrwx------ 4 postgres postgres 4.0K May 7 20:31 pg_multixactdrwx------ 2 postgres postgres 4.0K May 7 20:31 pg_notifydrwx------ 2 postgres postgres 4.0K May 7 20:42 pg_replslotdrwx------ 2 postgres postgres 4.0K May 7 20:31 pg_serialdrwx------ 2 postgres postgres 4.0K May 7 20:31 pg_snapshotsdrwx------ 2 postgres postgres 4.0K May 7 20:31 pg_statdrwx------ 2 postgres postgres 4.0K May 7 20:31 pg_stat_tmpdrwx------ 2 postgres postgres 4.0K May 7 20:31 pg_subtransdrwx------ 2 postgres postgres 4.0K May 7 20:31 pg_tblspcdrwx------ 2 postgres postgres 4.0K May 7 20:31 pg_twophase-rw------- 1 postgres postgres 3 May 7 20:31 PG_VERSIONdrwx------ 3 postgres postgres 4.0K May 7 21:13 pg_waldrwx------ 2 postgres postgres 4.0K May 7 20:31 pg_xact-rw------- 1 postgres postgres 3.2K May 7 20:31 postgresql.conf-rw------- 1 postgres postgres 0 May 7 20:31 standby.signal-rw------- 1 postgres postgres 0 May 7 20:42 tablespace_map-rw------- 1 postgres postgres. 2 May 7 20:31 TENCENTDB_RELEASE
[root@VM-10-5-tencentos recovery]# rm -rf backup_label
[root@VM-10-5-tencentos recovery]# vi postgresql.conf
pg_stat_statements.tracksynchronous_standby_namesextension_blacklistarchive_modebasebackup_exclude_pathstencentdb_syscache_max_numshared_preload_librariestencentdb_relcache_max_numarchive_commanddisable_dblink_connect_to_othertencentdb_az_fivetencentdb_az_fivetencentdb_relcache_evict_numpg_stat_statements.maxsoft_limit_connectionstencentdb_syscache_evict_numtencentdb_enable_trusted_extensionsynchronous_committencentdb_enable_superuser_unsafe_behaviourtencentdb_enable_copy_tolocal_preload_libraries
include = 'standby.conf'.log_destination = ‘csvlog’
port = '5433' ## Change the value of the port parameter to 5433.
synchronous_commit = localsynchronous_standby_names = ''
chmod 0700 /var/lib/pgsql/16/recoverychown postgres:postgres /var/lib/pgsql/16/recovery -R
[root@VM-10-5-tencentos recovery]# ls -altotal 4064drwx------ 19 postgres postgres 4096 May 8 09:43 .drwxr-xr-x 3 root root 4096 May 7 20:44 ..-rw------- 1 postgres postgres 225 May 7 20:42 backup_label-rw------- 1 postgres postgres 225 May 7 20:31 backup_label.olddrwx------ 6 postgres postgres 4096 May 7 21:13 base-rw------- 1 postgres postgres 56 May 7 20:31 current_audit_logfiles-rw------- 1 postgres postgres 35 May 7 20:31 current_logfilesdrwx------ 2 postgres postgres 4096 May 7 21:13 global-rw-r--r-- 1 postgres postgres 4045802 May 7 20:42 manual-20250507204222.tar.zstdrwx------ 2 postgres postgres 4096 May 7 20:31 pg_commit_tsdrwx------ 2 postgres postgres 4096 May 7 20:31 pg_dynshmem-rw------- 1 postgres postgres 308 May 7 20:31 pg_hba.conf-rw------- 1 postgres postgres 2640 May 7 20:31 pg_ident.confdrwx------ 4 postgres postgres 4096 May 7 20:31 pg_logicaldrwx------ 4 postgres postgres 4096 May 7 20:31 pg_multixactdrwx------ 2 postgres postgres 4096 May 7 20:31 pg_notifydrwx------ 2 postgres postgres 4096 May 7 20:42 pg_replslotdrwx------ 2 postgres postgres 4096 May 7 20:31 pg_serialdrwx------ 2 postgres postgres 4096 May 7 20:31 pg_snapshotsdrwx------ 2 postgres postgres 4096 May 7 20:31 pg_statdrwx------ 2 postgres postgres 4096 May 7 20:31 pg_stat_tmpdrwx------ 2 postgres postgres 4096 May 7 20:31 pg_subtransdrwx------ 2 postgres postgres 4096 May 7 20:31 pg_tblspcdrwx------ 2 postgres postgres 4096 May 7 20:31 pg_twophase-rw------- 1 postgres postgres 3 May 7 20:31 PG_VERSIONdrwx------ 3 postgres postgres 4096 May 7 21:13 pg_waldrwx------ 2 postgres postgres 4096 May 7 20:31 pg_xact-rw------- 1 postgres postgres 3276 May 7 21:35 postgresql.conf-rw------- 1 postgres postgres 0 May 7 20:31 standby.signal-rw------- 1 postgres postgres 0 May 7 20:42 tablespace_map-rw------- 1 postgres postgres 2 May 7 20:31 TENCENTDB_RELEASE
[root@VM-10-5-tencentos postgresql-16.8]# wget -O /var/lib/pgsql/16/recovery/pg_wal/file_name.tar.zst "download_address"
[root@VM-10-5-tencentos recovery]# cd /var/lib/pgsql/16/recovery/pg_wal[root@VM-10-5-tencentos pg_wal]# ls -lhtotal 33M-rw------- 1 postgres postgres 16M May 7 20:42 000000010000000000000003-rw------- 1 postgres postgres 16M May 7 20:42 000000010000000000000004-rw-r--r-- 1 root root 1.5K May 8 10:31 20250508103101_20250508103101-20250508101527-000000010000000000000005_000000010000000000000005.tar.zstdrwx------ 2 postgres postgres 4.0K May 7 21:13 archive_status
[root@VM-10-5-tencentos pg_wal]# tar -I zstd -xvf file_name.tar.zst000000010000000000000005
[root@VM-10-5-tencentos pg_wal]# ls -lhtotal 49M-rw------- 1 postgres postgres 16M May 7 20:42 000000010000000000000003-rw------- 1 postgres postgres 16M May 7 20:42 000000010000000000000004-rw------- 1 1003 users 16M May 8 10:31 000000010000000000000005-rw-r--r-- 1 root root 1.5K May 8 10:31 20250508103101_20250508103101-20250508101527-000000010000000000000005_000000010000000000000005.tar.zstdrwx------ 2 postgres postgres 4.0K May 7 21:13 archive_status
/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=>
[root@VM-10-5-tencentos ~]# pg_dump -h*.*.*.* -p 5432 -U dbadmin -Fc testdb > testdb_bkp.dumpPassword:
Parameter | Description |
host | The connection address of the TencentDB for PostgreSQL instance. If the cloud database and the CVM are in the same VPC, it is recommended to use the private network address for connection. |
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. |
[root@VM-10-5-tencentos ~]#ll testdb_bkp.dump
[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=#
Apakah halaman ini membantu?
Anda juga dapat Menghubungi Penjualan atau Mengirimkan Tiket untuk meminta bantuan.
masukan