PostgreSQL配置

 摘要

PostgreSQL配置

1、配置监听

-bash-4.2$ cd $PGDATA
-bash-4.2$ ls
base              pg_commit_ts   pg_logical    pg_serial     pg_subtrans  pg_wal                postmaster.opts
current_logfiles  pg_dynshmem    pg_multixact  pg_snapshots  pg_tblspc    pg_xact               postmaster.pid
global            pg_hba.conf    pg_notify     pg_stat       pg_twophase  postgresql.auto.conf
log               pg_ident.conf  pg_replslot   pg_stat_tmp   PG_VERSION   postgresql.conf

-bash-4.2$ cp postgresql.conf postgresql.conf.bak
-bash-4.2$ vi postgresql.conf 

listen_addresses = '*'  #监听所有ip

 数据库连接

-bash-4.2$ cp pg_hba.conf pg_hba.conf.bak
-bash-4.2$ vi pg_hba.conf
host    all             all             0.0.0.0/0               md5

多行参数生效顺序:由上到下

参数详解


查看数据库
-bash-4.2$ 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)

连接数据库

-bash-4.2$  psql -dpostgres
postgres=# h 可以查找命令
postgres=# ?

创建数据库

postgres=# create table test(id int);
CREATE TABLE
postgres=# dt
        List of relations
 Schema | Name | Type  |  Owner   
--------+------+-------+----------
 public | test | table | postgres
(1 row)

修改密码

postgres=# alter user postgres with password 'postgres';



原文地址:https://www.cnblogs.com/connected/p/12635678.html