Postgresql 8.2.15 installation documentation

1. Preparations

Environment: CentOS 6.8

turn off firewall

$: service iptables stop # 重启后失效
$: chkconfig iptables off # 禁用防火墙

Download the corresponding version tar package from the official website. This article uses postgresql 8.2.15 version: postgresql-8.2.15.tar.gz Official download website: https://www.postgresql.org/ftp/source/v8.2.15/

2. Install dependencies

$: yum -y install gcc
$: yum -y install gcc-c++
$: yum -y install readline-devel
$: yum -y install zlib-devel

3. Start the installation

3.1 Unzip the installation package The installation package is placed under /usr/local

$: cd /usr/local
$: tar -zvxf postgresql-8.2.15.tar.gz

Enter postgresql-8.2.15

$: cd postgresql-8.2.15

3.2 Create the Linux "postgres" user

$: adduser postgres
$: passwd postgres  # 创建用户密码

3.3 Start the installation in the /usr/local/postgresql-8.2.15 directory

$: cd /usr/local/postgresql-8.2.15
// 安装依赖
$: yum -y install make
// 配置
$: ./configure --prefix=/usr/local/postgresql
// 编译
$: make
// 安装
$: make install

3.4 Configure environment variables

$: vi /etc/profile
// 在/etc/profile文件的最后一行添加如下内容:
PATH=$PATH:/usr/local/postgresql/bin

Update environment variables:

$: source /etc/profile

3.5 Initialize the database

Initialize the database in the /usr/local/postgresql directory:

$: cd /usr/local/postgresql
$: mkdir data
$: chown postgres:postgres /usr/local/postgresql/data/
$: su postgres
$: /usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data/

3.6 Copy and modify the configuration file (modify the storage data directory)

Switch to the root user to copy and modify configuration files

$: su root 
$: “Password”  # 输入root密码

//复制安装目录下的linux文件到/etc/init.d/中,并将linux名称重命名为postgresql
$: cd /usr/local/postgresql-8.2.15 
$: cp /usr/local/postgresql-8.2.15/contrib/start-scripts/linux /etc/init.d/postgresql

//编辑复制出来的文件 
$: vi /etc/init.d/postgresql
//修改以下内容即可
# Installation prefix
prefix=/usr/local/postgresql
# Data directory
PGDATA="/usr/local/postgresql/data"
$: chmod +x /etc/init.d/postgresql

3.7 Start the database and set up auto-start

$: /etc/init.d/postgresql start
$: chkconfig postgresql on

3.8 Create a history file of database operations

$: touch /usr/local/postgresql/.pgsql_history
$: chown postgres:postgres /usr/local/postgresql/.pgsql_history 

3.9 Test whether the database is created successfully and connect to the database

$: cd /usr/local/postgresql-8.2.15 
$: su postgres
$: createdb test
$: psql test
// \q可以退出
Welcome to psql 8.2.15, the PostgreSQL interactive terminal.
Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit
test=# \q

4. Modify database external network access

4.1 Close the database before modifying the external network access of the database

$: su root 
$: “Password”  # 输入root密码
$: /etc/init.d/postgresql stop

4.2 Modify pg_hba.conf

$: vi /usr/local/postgresql/data/pg_hba.conf
// 找到IPv4 local connections
# IPv4 local connections:
host all all 127.0.0.1/32 trust
// 修改如下蓝色字体参数
# IPv4 local connections:
host all all 192.168.1.0/24 md5  #根据实际网段填写

4.3 Modify postgresql.conf

$: vi /usr/local/postgresql/data/postgresql.conf
// 找到listen_addresses:
# listen_addresses = 'localhost'
// 删除#号,更改如下
listen_addresses = '*'

4.4 Start postgresql again

$: /etc/init.d/postgresql start
$: su postgres  # 切换用户
$: psql -U postgres # 进入交互式
// 修改密码,本次密码设置为1234
alter user postgres with password '1234'; 
# \q  可以退出

4.5 After the installation is complete, we can also enter the host IP and enter postgresql through the following command

$: psql -h 192.168.1.XXX -d postgres -U postgres -p 5432
$: “Password”  # 输入刚更改的数据库用户postgres密码1234

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325445028&siteId=291194637