postgresql安装脚本 详情见postgresql-9.6.2一键安装脚本
使用方法
// 默认存放路径
/usr/local/sbin/install_pg.sh
// ...
// 脚本启动方法
sh /usr/local/sbin/install_pg.sh && . /etc/profile
注意事项
```
//脚本命名install_pg.sh,修改WEB 服务器IP,PG URL
//默认端口5432,可在脚本内修改端口修改脚本#配置编译参数:
./configure --prefix=${DST} --enable-debug --with-pgport= 5432 --with-tcl --with-perl --with-python --with-pam --with-openssl --with-libxml --with-libxslt --with-blocksize=16 --with-wal-blocksize=16
//创建PG 数据目录并将目录所属主和组都修改为 postgres:
mkdir -p /home/data/postgresql && chown -R postgres:postgres /home/data/postgresql
安装后配置允许访问IP
```
//修改postgres配置文件pg_hba.conf
上述路径:/home/data/postgresql/pg_hba.conf
在# Allow replication connections from localhost, by a user with the
# replication privilege.下添加
host all all 192.168.9.61/24 password
使用PostgreSQL控制台来操作
```
//首先切换到postgres用户下
su - postgres
//使用psql命令登陆PostgreSQL控制台
postgres=# psql
//为postgres用户设置一个密码(脚本自动生成密码存在/home/postgres/.PGPWD.txt)
postgres=# alter user postgres with password 'postgres';或者 \password postgres
//创建一个新数据库用户
postgres=# create user zylhz with password 'zylhz';
//查看数据库存在的用户及密码
postgres=# select * from pg_user;
postgres=# select * from pg_shadow;
//创建数据库
postgres=# create database zylhz;
//创建数据库并指定所有者为zylhz
postgres=# create database zylhzcom owner zylhz;
//查看存在的数据库
postgres=# \l
//赋zylhzcom数据库的所有权为zylhz
postgres=# grant ALL privileges on database zylhzcom to zylhz;
//切换至zylhz数据库
postgres=# \c zylhz
//插入数据
zylhz=# insert into test values (2,'zylhzcom');
//退出控制台
zylhz=# \q 或者 ctrl+d
使用shell命令行
```
//创建数据库用户,并指定其为超级用户
[root@kvm ~]# sudo -u postgres createuser -W -s zylhz3
//登陆数据库平台,设置密码
postgres=# \password zylhz3
//创建数据库,并指定所有者
[root@kvm ~]# sudo -u postgres createdb -O zylhz3 zylhzcom1
//登陆数据库
[root@kvm ~]# psql -d zylhzcom1 -U zylhz3 -h 127.0.0.1 -p 5432
PostgreSQL的登陆问题
```
//首先我们前面已经简单演示了postgresql的登陆
[root@kvm ~]# psql -d zylhzcom1 -U zylhz3 -h 127.0.0.1 -p 5432
上面命令的参数含义如下:-U指定用户,-d指定数据库,-h指定服务器,-p指定端口
输入以上的命令之后,系统会提示输入zylhz3的密码,输入正确,就可以登录控制台了。
```
文章参考:http://pangge.blog.51cto.com/6013757/1739794