Centos中PostgreSQL常用命令

1 查看

[root@April ~]# rpm -qa|grep postgresql
postgresql92-9.2.24-5PGDG.rhel6.i686
postgresql92-libs-9.2.24-5PGDG.rhel6.i686
postgresql92-server-9.2.24-5PGDG.rhel6.i686
postgresql92-contrib-9.2.24-5PGDG.rhel6.i686

2 初始化

[root@April ~]# service postgresql-9.2 initdb
Initializing database:                                     [  OK  ]

3 启动和停止

    启动服务

[root@April ~]# service postgresql-9.2 start
Starting postgresql-9.2 service:                           [  OK  ]

    停止服务

[root@April ~]# service postgresql-9.2 stop
Stopping postgresql-9.2 service:                           [  OK  ]

4 测试

[root@April ~]# su - postgres
-bash-4.1$ psql -l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 rows)

5 登录

    连接数据库postgres,用户名为postgres。

-bash-4.1$ psql -d postgres -U postgres
psql (9.2.24)
Type "help" for help

    退出psql

postgres=# \q
-bash-4.1$ 

6 退出

-bash-4.1$ exit
logout

7.开机启动

   设置开机启动

[root@April ~]# chkconfig postgresql-9.2 on

    关闭开机启动

[root@April ~]# chkconfig postgresql-9.2 off

    查看当前所有开机启动项

[root@April ~]# chkconfig --list

猜你喜欢

转载自blog.csdn.net/liyazhen2011/article/details/88967716