postgresql9.6安装

目前postgresql的最新版本已经是10.4 ;本次安装的版本是9.6,大版本之间还是有很多新特性的。


1、postgresql9.6的新功能:

 ①:并行查询

   并行查询是9.6版本的最大亮点。在之前的版本中,即使拥有多个空闲处理器,但数据库限制只能利用单个CPU的计算能力。9.6版本支持并行查询操作,因此能够利用服务器上的几个或所有CPU内核进行运算,这样讲更快返回查询结果。目前支持并行特性的操作有顺序表扫描、聚合和边接,根据操作细节和可用内核数目的不同,该并行特性可提高对大数据的检索效率,最快时可高达32倍左右。

   

 ②:同步复制功能的改进:

   postgresql的同步复制功能能得到改进,使它能够用于数据库集群一致读取的维护。首先,它现在允许配置同步复制组,其次,“remote_apply”模式通过多重节点创建一个更具统一性的实例。这些特性支持使用内置的自我复制功能来维护独立节点的负载均衡。

 ③:短语搜索

   postgresql的文本搜索功能,现在支持短语搜索。用户可以搜索精确的某个短语或者搜索有一定相似性的短语。

   使用快速的GIN索引中的单词,结合可精细调整的文本搜索的新功能,postgresql已经成为“混合搜索”的最佳选择。

 ④:更好的锁监控

   pg_stat_activity视图提供了更加详细的等待信息,当一个进程正在等待一个锁时,用户会看到锁的类型,以及将查询阻塞的等待事件的详细信息。此外,postgresql还增加了pg_blocking_pids()函数,可以知道哪些进程阻塞给定的服务器进程。

 ⑤:控制表膨胀

   到目前为止,一个长时间运行的显示查询结果的报告或游标均可能阻止失效行的清理,从而使数据库中经常变化的表膨胀,导致数据库的性能问题和存储空间的过度使用。

   9.6版本中添加了old_snapshot_threshold参数,可以将集群配置为允许在更新或删除事务时清除失效行,从而限制表膨胀。

   此外,9.6版本还添加了其他功能,例如,支持级联操作(需安装扩展模块实现),frozen页面更好的空间回收机制,只扫描局部索引,支持命令执行进度状态报告,外部排序操作的性能改进等。



--下载PG二进制软件包后,解压:

[root@localhost ~]# tar -zxvf postgresql-9.6.9-1-linux-x64-binaries.tar.gz -C /usr/src/

[root@localhost ~]# groupadd pguser

[root@localhost ~]# useradd -g pguser pguser

[root@localhost ~]# passwd pguser


[root@localhost ~]# su - pguser


--初始化PG数据库:

[pguser@localhost ~]$ cd /usr/src/pgsql/bin/
[pguser@localhost bin]$ ./initdb -E uft8 -D /pgsql/data/
The files belonging to this database system will be owned by user "pguser".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
initdb: "uft8" is not a valid server encoding name
[pguser@localhost bin]$ ./initdb -E utf8 -D /pgsql/data/
The files belonging to this database system will be owned by user "pguser".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /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:
    ./pg_ctl -D /pgsql/data/ -l logfile start
--:配置环境变量,~/.bash_profile 添加如下内容
PATH=/usr/local/pgsql/bin:$PATH
export PATH
--启动数据库:
[pguser@localhost ~]$ source .bash_profile 
[pguser@localhost ~]$ pg_ctl -D /pgsql/data/ -l /home/pguser/postgres.log start
server starting
或使用:
./postgres -D /pgsql/data > /pgsql/data/postgres.log &


注意:

当安装完数据库后,我们会有一个系统用户,一个数据库,一个数据库用户,他们默认的名称为:postgres


[root@localhost ~]# ps -ef |grep postgre

pguser    14160      1  0 01:36 pts/0    00:00:00 /usr/src/pgsql/bin/postgres -D /pgsql/data

pguser    14162  14160  0 01:36 ?        00:00:00 postgres: checkpointer process   

pguser    14163  14160  0 01:36 ?        00:00:00 postgres: writer process   

pguser    14164  14160  0 01:36 ?        00:00:00 postgres: wal writer process   

pguser    14165  14160  0 01:36 ?        00:00:00 postgres: autovacuum launcher process   

pguser    14166  14160  0 01:36 ?        00:00:00 postgres: stats collector process   

pguser    14246  14160  0 01:42 ?        00:00:00 postgres: pguser testdb [local] idle

root      14256  14009  0 01:42 pts/1    00:00:00 grep --color=auto postgre



--连接测试:

[pguser@localhost ~]$ psql --list

                               List of databases

   Name    | Owner  | Encoding |   Collate   |    Ctype    | Access privileges 

-----------+--------+----------+-------------+-------------+-------------------

 postgres  | pguser | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 

 template0 | pguser | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/pguser        +

           |        |          |             |             | pguser=CTc/pguser

 template1 | pguser | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/pguser        +

           |        |          |             |             | pguser=CTc/pguser

 testdb    | pguser | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 

(4 rows)



--登录数据库(从上面查看得知 postgres是一个数据库,)

[pguser@localhost ~]$ psql postgres

psql.bin (9.6.9)

Type "help" for help.


postgres=# select version();

                                                 version                                                  

----------------------------------------------------------------------------------------------------------

 PostgreSQL 9.6.9 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-16), 64-bit

(1 row)


postgres=# 

postgres=# \q    ---退出PG数据库:


或者创建一个db:

[pguser@localhost ~]$ createdb  testdb

[pguser@localhost ~]$ psql -d testdb   ---登录testdb

psql.bin (9.6.9)

Type "help" for help.


testdb=# select version();

                                                 version                                                  

----------------------------------------------------------------------------------------------------------

 PostgreSQL 9.6.9 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-16), 64-bit

(1 row)


testdb-# \q



pg_ctl -D /pgsql/data stop   --关闭PG数据库


注意:

   pgadmin 是一个设计、维护和管理postgresql数据库的通用工具,可以运行在Windows,Linux,freeBSD,mac,solaris平台上。pgadmin工具简单简易直观,可访问、查询、控制和管理数据库,同时还对多样化的图形工具与多种功能齐全的脚本编辑器进行整合,极大方便了各种开发人员对postgresql的访问。


猜你喜欢

转载自blog.51cto.com/fengfeng688/2148876