为postgreSQL命令添加man帮助

404 阅读2分钟

这是我参与8月更文挑战的第13天,活动详情查看:8月更文挑战

man命令是Linux系统下方便的查询相关命令帮助信息的命令,PG数据库也有自带的man帮助,通过简单的配置即可使用。 在解压postgreSQL的源码后,通过源码或编译好的二进制文件安装完postgreSQL后,通过yum或者rpm安装完postgreSQL后,会生成man手册,通过这个手册可以在手头没有对应版本的官方手册或者没有图形化环境的时候,快速并极其方便的查询PG的命令,库函数和语法的含义及使用。

方法很简单,通过修改man的配置文件即可。在man的配置文件中添加:

MANPATH /usr/local/pgsql/share/man

不同的系统man的配置文件可能会不同。

常见的为以下几种情况:

/etc/man.config

/etc/manpath.config

/etc/man_db.config

通过不同的方式安装,man手册位置也会有所不同,

默认的,

源码解压后在./postgresql-xxx/doc/src/sgml下。

源码安装后在/usr/local/pgsql/share/man下。

编译好的二进制文件安装后在/opt/PostgreSQL/版本号/share/man下。

yum或者rpm安装完后在/usr/local/pgsql/share/man下,这种情况下是自动配置好不需要修改man配置文件的。

[root@pg ~]# man psql
PSQL(1)                 PostgreSQL 9.4.14 Documentation                PSQL(1)

NAME
       psql - PostgreSQL interactive terminal

SYNOPSIS
       psql [option...] [dbname [username]]

DESCRIPTION
       psql is a terminal-based front-end to PostgreSQL. It enables you to type in queries interactively, issue them to PostgreSQL, and see the query
       results. Alternatively, input can be from a file. In addition, it provides a number of meta-commands and various shell-like features to
       facilitate writing scripts and automating a wide variety of tasks.
[root@pg ~]# man 3 dblink
DBLINK(3)               PostgreSQL 9.4.14 Documentation              DBLINK(3)

NAME
       dblink - executes a query in a remote database

SYNOPSIS
       dblink(text connname, text sql [, bool fail_on_error]) returns setof record
       dblink(text connstr, text sql [, bool fail_on_error]) returns setof record
[root@pg ~]# man 7 CREATE_DATABASE
CREATE DATABASE(7)      PostgreSQL 9.4.14 Documentation     CREATE DATABASE(7)

NAME
       CREATE_DATABASE - create a new database

SYNOPSIS
       CREATE DATABASE name
           [ [ WITH ] [ OWNER [=] user_name ]
                  [ TEMPLATE [=] template ]
                  [ ENCODING [=] encoding ]
                  [ LC_COLLATE [=] lc_collate ]
                  [ LC_CTYPE [=] lc_ctype ]
                  [ TABLESPACE [=] tablespace_name ]
                  [ CONNECTION LIMIT [=] connlimit ] ]