在CentOS7(虚拟机)下通过源码安装Postgresql10以及基本配置

操作系统:CentOS7
安装文件:postgresql-10.0.tar.gz

系统环境:gcc、Python

1:源码安装

[postgres@localhost ~]# tar zxvf postgresql-10.0.tar.gz
[postgres@localhost ~]# mv postgresql-10.0 /usr/local/pgsql/
[postgres@localhost ~]# cd /usr/local/pgsql/
[root@localhost pgsql]# ./configure --prefix=/usr/local/pgsql --without-readline --without-zlib
[root@localhost pgsql]# make
[root@localhost pgsql]# make install

2:添加postgres用户,设置目录权限

[root@localhost ~]# adduser postgres
[root@localhost ~]# passwd postgres
[root@localhost ~]# mkdir -p /usr/local/pgsql/data
[root@localhost ~]# chown -R posgres:root /usr/local/pgsql/
[root@localhost ~]# chown -R postgres:root /usr/local/pgsql/

3:设置环境变量

[root@localhost ~]# su - postgres
[postgres@localhost ~]$ vim ~/.bash_profile
PATH=$PATH:/usr/local/pgsql/bin
[postgres@localhost ~]$ source ~/.bash_profile 

4:添加启动服务

1)添加启动服务
[root@localhost ~]# cp /usr/local/pgsql/contrib/start-scripts/linux /etc/init.d/postgresql
[root@localhost ~]# chmod u+x /etc/init.d/postgresql 
(2)添加开机自启动
[root@localhost ~]# chkconfig --add postgresql
(3)启动服务
[root@localhost ~]# service postgresql start
Starting PostgreSQL: ok

5:切换到postgres用户,初始化数据库

[postgres@localhost data]$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "zh_CN.UTF-8".
The default database encoding has accordingly been set to "UTF8".
initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
The default text search configuration will be set to "simple".

Data page checksums are disabled.

fixing permissions on existing directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start

6:修改postgresql配置

1)允许所有连接
[postgres@localhost ~]$ vi /usr/local/pgsql/data/pg_hba.conf
# IPv4 local connections:
host    all             all             0.0.0.0/0            trust
(2)侦听所有连接
[postgres@localhost ~]$ vi /usr/local/pgsql/data/postgresql.conf
listen_addresses = '*'
logging_collector = on

7:启动数据库

[postgres@localhost data]$  /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
waiting for server to start.... done
server started

8:设置postgres用户的密码

[postgres@localhost ~]$ psql 
psql (10.0)
Type "help" for help.

postgres=# \password
Enter new password: 
Enter it again:

9:查看当前数据库列表

10:创建角色、数据库,切换数据库、用户

postgres=# create role test login password 'test';   
CREATE ROLE
postgres=# create database testdb with owner=test;
CREATE DATABASE
postgres=# \c testdb;
You are now connected to database "testdb" as user "postgres".
testdb=# \c - test;
You are now connected to database "testdb" as user "test".
testdb=>

11:本地通过pgAdmin4进行连接

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值