Installation configuration under centos

Step 1: Create a new data and logs folder in the installation directory

 

mkdir -p /home/postgres/9.5.3/data  /home/postgres/9.5.3/logs
Step 2: Write the new configuration postgresq configuration in the .bash_profile file

 

# postsql config
PGDATA=/home/hous/postgresql/9.5.3//data
PATH=$PATH:/home/hous/postgresql/9.5.3//bin
export PGDATA PATH

Step 3: Initialize data and start the database service

 

/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 &
or
http://blog.csdn.net/anzelin_ruc/article/details/8625174
  Step 4: Create a database, add roles and passwords

 

/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;

 Step 5: Modify the remote connection method. Assuming that the IP address of 192.168.*.* needs to access the database, the content of the pg_hba.conf file needs to be modified.

 

echo 'host all all 192.168.0.0/16 password' >> /home/postgres/9.5.3/data/pg_hba.conf
 1) Monitor all ports in the data/postgresql.conf file 2) Whether the firewall opens the database port to the outside world, or directly closes the auto-config.sh automatic configuration file written by yourself, it must be placed in the installation directory
#! /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 &

  Initialize database related operations 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
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326783010&siteId=291194637