第一步:安装目录下新建data和logs文件夹
mkdir -p /home/postgres/9.5.3/data /home/postgres/9.5.3/logs第二步:在.bash_profile文件中写入新的配置postgresq配置
# postsql config PGDATA=/home/hous/postgresql/9.5.3//data PATH=$PATH:/home/hous/postgresql/9.5.3//bin export PGDATA PATH
第三步:初始化data,启动数据库服务
/home/postgres/9.5.3/bin/initdb -D /home/postgres/9.5.3/data
nohup ./bin/postgres -D /home/postgres/9.5.3/data > ./logs/logfile 2>&1 & 或者 http://blog.csdn.net/anzelin_ruc/article/details/8625174第四步:创建数据库,添加角色和密码
/home/postgres/9.5.3/bin/createdb mydb /home/postgres/9.5.3/bin/psql mydb psql (9.5.3) Type "help" for help. mydb=# create role myrole with login password '密码'; mydb=# create schema myschema authorization myrole;
第五步:修改远程连接方式,假设需要让192.168.*.*的IP地址访问该数据库,需修改pg_hba.conf文件内容.
echo 'host all all 192.168.0.0/16 password' >> /home/postgres/9.5.3/data/pg_hba.conf1)data/postgresql.conf文件中监听所有端口 2)防火墙是否对外开放数据库端口,或者直接关闭 自己写的auto-config.sh自动配置文件,一定要放在安装的目录下
#! /bin/bash # program: # config postgresql PG_HOME=$(pwd) # step1: mkdir -p data logs # step2: echo -e '\n# postgresql config' >> ~/.bash_profile echo 'PGDATA='"$PG_HOME"'/data' >> ~/.bash_profile echo 'PATH=$PATH:'"$PG_HOME"'/bin' >> ~/.bash_profile echo 'export PGDATA PATH' >> ~/.bash_profile source ~/.bash_profile # step3: ./bin/initdb -D ./data nohup ./bin/postgres -D ./data > ./logs/logfile 2>&1 &初始化数据库相关操作init-db.sh
#! /bin/bash # Program # init postgresql create db,role,schema # ./bin/createdb mydb # init-db.sql content below # create role myrole with login password '123456'; # create schema myschema authorization 'myrole'; ./bin/createdb mydb ./bin/psql -d mydb -f ./init-db.sql