標籤:arc 事務 pos sel nta 快速 bsp miss clust
目前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二進位軟體包後,解壓:
[[email protected] ~]# tar -zxvf postgresql-9.6.9-1-linux-x64-binaries.tar.gz -C /usr/src/
[[email protected] ~]# groupadd pguser
[[email protected] ~]# useradd -g pguser pguser
[[email protected] ~]# passwd pguser
[[email protected] ~]# su - pguser
--初始化PG資料庫:
[[email protected] ~]$ cd /usr/src/pgsql/bin/[[email protected] 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[[email protected] 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 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... oksyncing data to disk ... okWARNING: enabling "trust" authentication for local connectionsYou 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:$PATHexport PATH--啟動資料庫:[[email protected] ~]$ source .bash_profile [[email protected] ~]$ pg_ctl -D /pgsql/data/ -l /home/pguser/postgres.log startserver starting或使用:./postgres -D /pgsql/data > /pgsql/data/postgres.log &
注意:
當安裝完資料庫後,我們會有一個系統使用者,一個資料庫,一個資料庫使用者,他們預設的名稱為:postgres
[[email protected] ~]# 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
--串連測試:
[[email protected] ~]$ 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是一個資料庫,)
[[email protected] ~]$ 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:
[[email protected] ~]$ createdb testdb
[[email protected] ~]$ 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的訪問。
postgresql9.6安裝