环境准备
服务器 :Linux SUSE 11
版本 :PostgreSQL 10.3
1、下载最新版本 postgresql-10.3.tar.gz
有网则:
wget https://ftp.postgresql.org/pub/source/v10.3/postgresql-10.3.tar.gz
没网:windows下载上传到linux 指定文件夹
2、创建postgres用户和组 解压文件
groupadd postgres
useradd -g postgres postgres
chown postgres:postgres /home/super/soft/pgdatabase -R
cd /home/super/soft
tar -zxvf postgresql-10.3.tar.gz
-z :有gzip属性的
-x:解压
-v:显示所有过程
-f: 使用档案名字,切记,这个参数是最后一个参数,后面只能接档案名。
3、编译
cd home/super/soft/postgresql-10.3
./configure --prefix=/home/super/soft/postgreSql10 --without-readline -E zh_CN.GBK
./configure 用于linux安装文件的环境配置检测
--prefix 用于指定文件目录
--without-readline 表示忽略该依赖readline 文件的检查
问题1:
4、下载该软件 zlib-1.2.11.tar.gz,并解压
tar zlib-1.2.11
cd zlib-1.2.11/
./configure
make && make install
回到pgsql解压后的目录,重新执行 ./configure 检测,编译
./configure --prefix=/home/super/soft/postgreSql10 --without-readline
make && make install
5、设置环境变量,否则无法执行initdb等命令
Ø cd /etc
Ø vi profile
Ø export PGHOME=/home/super/soft/postgresql-10.3
Ø export PGDATA=~/home/super/soft/pgdatabase
Ø export PATH=$PATH:$HOME/bin:/home/super/soft/postgreSql10/bin
Ø export PG_PATH=/home/super/soft/postgreSql10/bin
Ø export PATH=$PG_PATH:$PATH
加入后通过按 esc 按:wq保存并退出,通过source /etc/profile
6、初始化数据库,不支持中文,需设置utf8
initdb -D /home/super/soft/pgdatabase -E UTF-8 --locale=zh_CN.UTF-8
7、修改默认配置文件的端口和监听
进入pgsql的数据库安装目录下打开 客户端认证配置 pg_hba.conf 文件 添加需要连接的地址
方法需设置为trust ,则该IP可通过远程连接
8、启动 PostgreSQL
pg_ctl -D /home/super/soft/pgdatabase/ start
关闭
pg_ctl -D /home/super/soft/pgdatabase/ stop
重启
pg_ctl -D /home/super/soft/pgdatabase/ reload
9、 查看当前数据库的状态
ps -ef|grep postgres
10、连接数据库测试
psql -p 5432 -U postgres -d postgres
create database test;
\l
11、创建角色
CREATE ROLE postgres login replication encrypted password '123456'
12、修改用户密码
首先把该IP地址设为trust ,其次登陆postgresql 执行sql
Ø ALTER USER postgres WITH PASSWORD 'postgres';