postgresql安装概览

先从官网下载解压包:https://www.enterprisedb.com/download-postgresql-binaries

这种是解压后,进行配置就可以使用。

另外一种是要用./configure编译安装的:https://www.postgresql.org/ftp/source/v9.5.6/

解压后得到以下文件:

tar -zvxf postgresql-9.5.14-1.tar.gz

  

其中.bash_profile是没有的,是自己配置的。

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PGHOME=/data/postgresql/pgsql
export PGHOME

export PGDATA=$PGHOME/data_hjf

PATH=$PATH:$HOME/bin:$PGHOME/bin

export PATH

首先在root用户的时候创建数据库文件存放位置:

mkdir data_hjf

创建postgres用户,并设置权限:

groupadd postgres
useradd -g postgres postgres
sudo chown -R postgres:postgres /data/postgresql/
sudo chmod 700 /data/postgresql/

然后切换到postgres进行操作:

su postgres

先使得.bash_profile生效:

source ./.bash_profile

去到bin目录,初始化数据库并设定数据库编码:

initdb -E UTF-8 -D data7 --locale=zh_CN.UTF-8

查看版本,注意是大写V:

psql -V

然后启动停止重启:

pg_ctl start
pg_ctl stop
pg_ctl restart

然后就可以用psql命令访问了:

[postgres@dev49 /data/postgresql/pgsql/bin]$ psql

猜你喜欢

转载自www.cnblogs.com/stuhjf/p/9487266.html