Postgresql - Client and Server Applications - Commands

OS: MacOS

Version: 11.1

Client Applications

clusterdb

作用:cluster a PostgreSQL database

用法1:clusterdb test # cluster 整库

用法2:clusterdb --table=foo test # cluster 库里的一个表

createdb

作用:create a new PostgreSQL database

用法:createdb -U dbadmin -T template0 -e demo --lc-collate=C --lc-ctype=C --owner=mytest

createuser

作用:define a new PostgreSQL user account

用法:createuser -h eden -p 5000 -S -D -R -e joe

dropdb

作用:remove a PostgreSQL database

用法:dropdb -U dbadmin demo

dropuser

作用:remove a PostgreSQL user account

用法:dropuser -U dbadmin mytest

ecpg

作用:embedded SQL C preprocessor

用法:ecpg prog1.pgc

pg_basebackup

作用: take a base backup of a PostgreSQL cluster

用法1:pg_basebackup -h 192.168.13.53 -U dbsr -F p -P -R -D /usr/local/pgsql/data

用法2:pg_basebackup -D backup -Ft -z -P

pg_bench

作用:run a benchmark test on PostgreSQL

用法:pgbench -i -U dbadmin -d db_test --foreign-keys --scale=100 --fillfactor=60

--------------------------------

dropping old tables...

NOTICE: table "pgbench_accounts" does not exist, skipping

NOTICE: table "pgbench_branches" does not exist, skipping

NOTICE: table "pgbench_history" does not exist, skipping

NOTICE: table "pgbench_tellers" does not exist, skipping

creating tables...

generating data...

100000 of 100000 tuples (100%) done (elapsed 0.16 s, remaining 0.00 s)

vacuuming...

creating primary keys...

done.

--------------------------------

pg_config

作用: retrieve information about the installed version of PostgreSQL

用法:pg_config --docdir --bindir --htmldir --pkgincludedir --includedir-server --libdir --pkglibdir --localedir --mandir --sharedir --sysconfdir --pgxs --configure --cc .......

pg_dump

作用: extract a PostgreSQL database into a script file or other archive file

用法1:pg_dump -Fc mydb -f db.dump

用法2:pg_dump -U dbadmin -d mydb -T 'test*' -f test.sql # 以

用法3:pg_dump -U dbadmin -d mydb -t test01 -f test01.sql

pg_dumpall

作用: extract a PostgreSQL database cluster into a script file

用法1:pg_dumpall -U dbadmin -f db.sql

用法2:pg_dumpall -U postgres -g -f golbal_data.sql

pg_isready

作用:check the connection status of a PostgreSQL server

用法:pg_isready -h host01 -p 5432

pg_receivewal

作用:stream write-ahead logs from a PostgreSQL server

说明:pg_receivewal用于流式传输正在运行的PostgreSQL集群中的提前写入日志。提前写入日志使用流式复制协议进行流式处理,并写入本地文件目录。此目录可用作使用时间点恢复进行恢复的存档位置。pg_receivewal实时地流式处理预写日志,因为它是在服务器上生成的,并且不像archive_命令那样等待段完成。因此,在使用pg_receivewal时,不需要设置存档超时。与PostgreSQL备用服务器的wal接收器不同,pg_receivewal默认情况下只在关闭wal文件时刷新wal数据。必须指定选项--synchronous以实时刷新wal数据。

用法:

pg_recvlogical

作用:control PostgreSQL logical decoding streams

说明:pg逻辑控制逻辑解码复制槽,并从这些复制槽流数据。

用法:

pg_restore

作用:restore a PostgreSQL database from an archive file created by pg_dump

用法:pg_restore -U dbadmin -h host -j 12 -Fc -d dbname dbname.dmp

pgbench

作用:

用法:pgbench -i -U dbadmin -d db_test --foreign-keys --scale=100 --fillfactor=60

--------------------------------

dropping old tables...

NOTICE: table "pgbench_accounts" does not exist, skipping

NOTICE: table "pgbench_branches" does not exist, skipping

NOTICE: table "pgbench_history" does not exist, skipping

NOTICE: table "pgbench_tellers" does not exist, skipping

creating tables...

generating data...

100000 of 100000 tuples (100%) done (elapsed 0.16 s, remaining 0.00 s)

vacuuming...

creating primary keys...

done.

--------------------------------

psql

作用:PostgreSQL interactive terminal

用法1:psql -U dbadmin -d postgres -h host -p 5432

reindexdb

作用: reindexdb is a utility for rebuilding indexes in a PostgreSQL database.

用法:reindexdb -U dbadmin -d mytest --table=test --index=test_id_idx

vacuumdb

作用:garbage-collect and analyze a PostgreSQL database

用法:vacuumdb --analyze --verbose --table='foo(bar)' xyzzy

oid2name

作用:resolve OIDs and file nodes in a PostgreSQL data directory

用法1:oid2name

用法2:oid2name -d mytest -t test01

vacuumlo

作用:remove orphaned large objects from a PostgreSQL database

说明:vacuumlo是一个简单的实用程序,可以从PostgreSQL数据库中删除任何“孤立”的大型对象。孤立大对象(LO)被认为是其OID未出现在数据库的任何OID或LO数据列中的任何LO。

用法:

Server Applications

initdb

作用:create a new PostgreSQL database cluster

用法:

pg_archivecleanup

作用:clean up PostgreSQL WAL archive files

说明:当作为备用服务器运行时,pg_archive clean up被设计成一个archive_clean up_命令来清理wal文件归档。pg_archivecleanup也可以作为一个独立的程序来清理wal文件档案。

要将备用服务器配置为使用pg_archivecleanup,放入recovery.conf配置文件。

用法1:pg_archivecleanup -d archive 000000010000003700000010.00000020.backup

用法2:archive_cleanup_command = 'pg_archivecleanup -d /mnt/standby/archive %r 2>>cleanup.log'

pg_controldata

作用: display control information of a PostgreSQL database cluster

用法:pg_controldata

pg_ctl

作用: initialize, start, stop, or control a PostgreSQL server

用法:

pg_ctl init[db] [-D datadir] [-s] [-o initdb-options]

pg_ctl start [-D datadir] [-l filename] [-W] [-t seconds] [-s] [-o options] [-p path] [-c]

pg_ctl stop [-D datadir] [-m s[mart] | f[ast] | i[mmediate] ] [-W] [-t seconds] [-s]

pg_ctl restart [-D datadir] [-m s[mart] | f[ast] | i[mmediate] ] [-W] [-t seconds] [-s] [-o options] [-c]

pg_ctl reload [-D datadir] [-s]

pg_ctl status [-D datadir]

pg_ctl promote [-D datadir] [-W] [-t seconds] [-s]

pg_ctl kill signal_name process_id

On Microsoft Windows, also:

pg_ctl register [-D datadir] [-N servicename] [-U username] [-P password] [-S a[uto] | d[emand] ] [-e source] [-W] [-t seconds] [-s] [-o options]

pg_ctl unregister [-N servicename]

pg_resetwal

作用: reset the write-ahead log and other control information of a PostgreSQL database cluster

说明:服务器运行时不得使用此命令。

用法:pg_resetwal -D /usr/local/pgsql/data/

pg_rewind

作用:synchronize a PostgreSQL data directory with another data directory that was forked from it

说明:pg_rewind是一个工具,用于在集群的时间线出现分歧后,将PostgreSQL集群与同一集群的另一个副本进行同步。一个典型的场景是,在故障转移之后,将旧的主服务器作为新主服务器之后的备用服务器重新联机。结果相当于用源数据目录替换目标数据目录。只复制来自关系文件的已更改块;所有其他文件(包括配置文件)都将被完整复制。与使用新的基本备份或rsync等工具相比,pg_rewind的优势在于pg_rewind不需要读取集群中未更改的块。这使得当数据库很大时速度更快,并且集群之间只有很小一部分块不同。pg_rewind检查源集群和目标集群的时间线历史,以确定它们的分歧点,并期望在目标集群的pg_wal目录中找到wal,一直延伸到分歧点。分歧点可以在目标时间线、源时间线或它们的共同祖先上找到。在典型的故障转移场景中,目标集群在分歧后很快关闭,这不是问题,但是如果目标集群在分歧后运行很长时间,那么旧的wal文件可能不再存在。在这种情况下,可以手动将它们从wal归档文件复制到pg_wal目录,或者通过配置recovery.conf在启动时获取。pg_w rewind的使用不仅限于故障转移,例如,可以升级备用服务器,运行一些写事务,然后重新倒带以再次成为备用服务器。当目标服务器在运行pg_rewind后第一次启动时,它将进入恢复模式,并在偏离点后重放源服务器中生成的所有wal。如果在运行pg_rewind时,源服务器中的某些wal不再可用,因此pg_rewind会话无法复制,则必须在启动目标服务器时使其可用。这可以通过使用合适的restore_command 在目标数据目录中创建recovery.conf文件来完成。pg_rewind要求目标服务器在postgresql.conf中启用wal_log_hints选项,或者在使用initdb初始化集群时启用数据校验和。默认情况下,这两个选项都当前处于打开状态。完整的页面写入也必须设置为打开,但默认情况下是启用的。

用法:pg_rewind --target-pgdata $PGDATA --source-server='host=db1 port=5432 user=postgres dbname=postgres' -P

pg_test_fsync

作用:determine fastest wal_sync_method for PostgreSQL

说明:了解特定系统上最快的wal-sync方法,并在识别出I/O问题时提供诊断信息。然而,pg_test_fsync 所显示的差异可能不会对实际数据库吞吐量产生任何显著的影响,特别是因为许多数据库服务器的速度不受其提前写入日志的限制。pg_test_fsync 以微秒为单位报告每个 wal_sync_method 的平均文件同步操作时间,这也可用于通知优化提交延迟值的工作。

用法:pg_test_fsync

pg_test_timing

作用:measure timing overhead

说明:pg_test_timing是一个工具,用于测量系统上的计时开销,并确认系统时间不会向后移动。收集定时数据速度较慢的系统可以给出不太准确的解释分析结果。

用法:pg_test_timing

pg_upgrade

作用:upgrade a PostgreSQL server instance

用法:

pg_verify_checksums

作用:verify data checksums in a PostgreSQL database cluster

说明:cluster must be shut down to verify checksums

用法:pg_verify_checksums

pg_waldump

作用:display a human-readable rendering of the write-ahead log of a PostgreSQL database cluster

用法1:pg_waldump -b 000000010000000100000030 000000010000000100000031

用法2:pg_waldump -b --start=1/304B2C20 --end=1/304B2DA8

用法3:pg_waldump -b -f -r Transaction 00000001000000010000003

postgres

作用:

用法:

postmaster

作用:

用法:

pg_standby

作用:supports the creation of a PostgreSQL warm standby server

用法:

猜你喜欢

转载自blog.csdn.net/chuckchen1222/article/details/86507823