第 4 課 PostgreSQL 安裝最新的版本

1. 打開(kāi)官網(wǎng)

https://www.postgresql.org/

2. 點(diǎn)擊download

image.png

3. 選擇版本類(lèi)型

根據(jù)實(shí)際情況選擇你的目標(biāo)主機(jī)類(lèi)型速勇,我的是Centos锚扎,所以選擇Red Hat.


image.png

4. 選擇系統(tǒng)配置

選擇后會(huì)生成對(duì)對(duì)應(yīng)的rpm URL地址。


image.png

5. 安裝rpm

復(fù)制rpm命令箩朴,在系統(tǒng)下執(zhí)行岗喉,保證主機(jī)有聯(lián)網(wǎng)。提示輸入: y

yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm

6. 安裝postgresql

安裝客戶(hù)端:

yum install postgresql10
image.png

安裝服務(wù)器端:

yum install postgresql10-server
image.png

7. 啟動(dòng)postgresql

初始化啟動(dòng)數(shù)據(jù)庫(kù)

/usr/pgsql-10/bin/postgresql-10-setup initdb
image.png

初始化成功后:數(shù)據(jù)庫(kù)目錄在:/var/lib/pgsql/10炸庞, data目錄

drwx------ 5 postgres postgres  4096 Jul 30 15:52 base
-rw------- 1 postgres postgres    30 Jul 30 15:55 current_logfiles
drwx------ 2 postgres postgres  4096 Jul 30 16:02 global
drwx------ 2 postgres postgres  4096 Jul 30 15:55 log
drwx------ 2 postgres postgres  4096 Jul 30 15:52 pg_commit_ts
drwx------ 2 postgres postgres  4096 Jul 30 15:52 pg_dynshmem
-rw------- 1 postgres postgres  4269 Jul 30 15:52 pg_hba.conf
-rw------- 1 postgres postgres  1636 Jul 30 15:52 pg_ident.conf
drwx------ 4 postgres postgres  4096 Jul 30 17:10 pg_logical
drwx------ 4 postgres postgres  4096 Jul 30 15:52 pg_multixact
drwx------ 2 postgres postgres  4096 Jul 30 15:55 pg_notify
drwx------ 2 postgres postgres  4096 Jul 30 15:52 pg_replslot
drwx------ 2 postgres postgres  4096 Jul 30 15:52 pg_serial
drwx------ 2 postgres postgres  4096 Jul 30 15:52 pg_snapshots
drwx------ 2 postgres postgres  4096 Jul 30 15:52 pg_stat
drwx------ 2 postgres postgres  4096 Jul 30 17:15 pg_stat_tmp
drwx------ 2 postgres postgres  4096 Jul 30 15:52 pg_subtrans
drwx------ 2 postgres postgres  4096 Jul 30 15:52 pg_tblspc
drwx------ 2 postgres postgres  4096 Jul 30 15:52 pg_twophase
-rw------- 1 postgres postgres     3 Jul 30 15:52 PG_VERSION
drwx------ 3 postgres postgres  4096 Jul 30 15:52 pg_wal
drwx------ 2 postgres postgres  4096 Jul 30 15:52 pg_xact
-rw------- 1 postgres postgres    88 Jul 30 15:52 postgresql.auto.conf
-rw------- 1 postgres postgres 22761 Jul 30 15:52 postgresql.conf
-rw------- 1 postgres postgres    58 Jul 30 15:55 postmaster.opts
-rw------- 1 postgres postgres   103 Jul 30 15:55 postmaster.pid

設(shè)置自動(dòng)啟動(dòng)配置:

systemctl enable postgresql-10

啟動(dòng)服務(wù)器:

systemctl start postgresql-10

查看運(yùn)行狀態(tài):

systemctl status postgresql-10
image.png

查看進(jìn)程:

ps -ef|grep postgres
image.png

8. 使用psql連接數(shù)據(jù)庫(kù)

在UNIX平臺(tái)中安裝PostgreSQL之后钱床,PostgreSQL會(huì)在UNIX系統(tǒng)中創(chuàng)建一個(gè)名為“postgres”當(dāng)用戶(hù)。PostgreSQL的默認(rèn)用戶(hù)名和數(shù)據(jù)庫(kù)也是“postgres”埠居,
不過(guò)沒(méi)有默認(rèn)密碼查牌。在安裝PostgreSQL之后可以默認(rèn)用戶(hù)登錄事期,也可以創(chuàng)建新當(dāng)用戶(hù)名。

[root@izwz90tx4egvh4qj3p95vsz ~]# sudo su postgres
bash-4.2$ 
bash-4.2$ 
bash-4.2$ psql postgres
could not change directory to "/root": Permission denied
psql (10.4)
Type "help" for help.

postgres=# select version(); --查看版本
                                                 version                                                 
---------------------------------------------------------------------------------------------------------
 PostgreSQL 10.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28), 64-bit
(1 row)

postgres=# \l  --查看所有數(shù)據(jù)庫(kù)
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 rows)

postgres=# \dn  --查看模式
  List of schemas
  Name  |  Owner   
--------+----------
 public | postgres
(1 row)

postgres=# \q --退出
bash-4.2$ 

查看更多命令參數(shù):

bash-4.2$ psql -?   --查看幫助
psql is the PostgreSQL interactive terminal.

Usage:
  psql [OPTION]... [DBNAME [USERNAME]]

General options:
  -c, --command=COMMAND    run only single command (SQL or internal) and exit
  -d, --dbname=DBNAME      database name to connect to (default: "postgres")
  -f, --file=FILENAME      execute commands from file, then exit
  -l, --list               list available databases, then exit
  -v, --set=, --variable=NAME=VALUE
                           set psql variable NAME to VALUE
                           (e.g., -v ON_ERROR_STOP=1)
  -V, --version            output version information, then exit
  -X, --no-psqlrc          do not read startup file (~/.psqlrc)
  -1 ("one"), --single-transaction
                           execute as a single transaction (if non-interactive)
  -?, --help[=options]     show this help, then exit
      --help=commands      list backslash commands, then exit
      --help=variables     list special variables, then exit

Input and output options:
  -a, --echo-all           echo all input from script
  -b, --echo-errors        echo failed commands
  -e, --echo-queries       echo commands sent to server
  -E, --echo-hidden        display queries that internal commands generate
  -L, --log-file=FILENAME  send session log to file
  -n, --no-readline        disable enhanced command line editing (readline)
  -o, --output=FILENAME    send query results to file (or |pipe)
  -q, --quiet              run quietly (no messages, only query output)
  -s, --single-step        single-step mode (confirm each query)
  -S, --single-line        single-line mode (end of line terminates SQL command)

Output format options:
  -A, --no-align           unaligned table output mode
  -F, --field-separator=STRING
                           field separator for unaligned output (default: "|")
  -H, --html               HTML table output mode
  -P, --pset=VAR[=ARG]     set printing option VAR to ARG (see \pset command)
  -R, --record-separator=STRING
                           record separator for unaligned output (default: newline)
  -t, --tuples-only        print rows only
  -T, --table-attr=TEXT    set HTML table tag attributes (e.g., width, border)
  -x, --expanded           turn on expanded table output
  -z, --field-separator-zero
                           set field separator for unaligned output to zero byte
  -0, --record-separator-zero
                           set record separator for unaligned output to zero byte

Connection options:
  -h, --host=HOSTNAME      database server host or socket directory (default: "local socket")
  -p, --port=PORT          database server port (default: "5432")
  -U, --username=USERNAME  database user name (default: "postgres")
  -w, --no-password        never prompt for password
  -W, --password           force password prompt (should happen automatically)

For more information, type "\?" (for internal commands) or "\help" (for SQL
commands) from within psql, or consult the psql section in the PostgreSQL
documentation.

Report bugs to <pgsql-bugs@postgresql.org>.

連接服務(wù)器后纸颜,使用 "\?" 命令查看更多參數(shù):

bash-4.2$ psql postgres
psql (10.4)
Type "help" for help.

postgres=# \?
General
  \copyright             show PostgreSQL usage and distribution terms
  \crosstabview [COLUMNS] execute query and display results in crosstab
  \errverbose            show most recent error message at maximum verbosity
  \g [FILE] or ;         execute query (and send results to file or |pipe)
  \gexec                 execute query, then execute each value in its result
  \gset [PREFIX]         execute query and store results in psql variables
  \gx [FILE]             as \g, but forces expanded output mode
  \q                     quit psql
  \watch [SEC]           execute query every SEC seconds

Help
  \? [commands]          show help on backslash commands
  \? options             show help on psql command-line options
  \? variables           show help on special variables
  \h [NAME]              help on syntax of SQL commands, * for all commands

Query Buffer
  \e [FILE] [LINE]       edit the query buffer (or file) with external editor
  \ef [FUNCNAME [LINE]]  edit function definition with external editor
  \ev [VIEWNAME [LINE]]  edit view definition with external editor
  \p                     show the contents of the query buffer
  \r                     reset (clear) the query buffer
  \s [FILE]              display history or save it to file
  \w FILE                write query buffer to file

Input/Output
  \copy ...              perform SQL COPY with data stream to the client host
  \echo [STRING]         write string to standard output
  \i FILE                execute commands from file
  \ir FILE               as \i, but relative to location of current script
  \o [FILE]              send all query results to file or |pipe
  \qecho [STRING]        write string to query output stream (see \o)

Conditional
  \if EXPR               begin conditional block
  \elif EXPR             alternative within current conditional block
  \else                  final alternative within current conditional block
  \endif                 end conditional block

Informational
  (options: S = show system objects, + = additional detail)
--More--

例如:查看所有函數(shù):

postgres=# \df *
                                                                                                                                                 
                                                                                                                                                 
                                                          List of functions
   Schema   |                     Name                     |         Result data type          |                                                 
                                                                                                                                                 
                                                                                                    Argument data types                          
                                                                                                                                                 
                                                                                                                           |  Type   
------------+----------------------------------------------+-----------------------------------+-------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------+---------
 pg_catalog | RI_FKey_cascade_del                          | trigger                           |                                                 
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                           | trigger
 pg_catalog | RI_FKey_cascade_upd                          | trigger                           |                                                 
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                           | trigger
 pg_catalog | RI_FKey_check_ins                            | trigger                           |                                                 
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                           | trigger
 pg_catalog | RI_FKey_check_upd                            | trigger                           |                                                 
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                                                 
                                                                                                                           | trigger

模糊匹配查看函數(shù):

postgres=# \df ab*
                                 List of functions
   Schema   |    Name     | Result data type |     Argument data types     |  Type  
------------+-------------+------------------+-----------------------------+--------
 pg_catalog | abbrev      | text             | cidr                        | normal
 pg_catalog | abbrev      | text             | inet                        | normal
 pg_catalog | abs         | bigint           | bigint                      | normal
 pg_catalog | abs         | double precision | double precision            | normal
 pg_catalog | abs         | integer          | integer                     | normal
 pg_catalog | abs         | numeric          | numeric                     | normal
 pg_catalog | abs         | real             | real                        | normal
 pg_catalog | abs         | smallint         | smallint                    | normal
 pg_catalog | abstime     | abstime          | timestamp without time zone | normal
 pg_catalog | abstime     | abstime          | timestamp with time zone    | normal
 pg_catalog | abstimeeq   | boolean          | abstime, abstime            | normal
 pg_catalog | abstimege   | boolean          | abstime, abstime            | normal
 pg_catalog | abstimegt   | boolean          | abstime, abstime            | normal
 pg_catalog | abstimein   | abstime          | cstring                     | normal
 pg_catalog | abstimele   | boolean          | abstime, abstime            | normal
 pg_catalog | abstimelt   | boolean          | abstime, abstime            | normal
 pg_catalog | abstimene   | boolean          | abstime, abstime            | normal
 pg_catalog | abstimeout  | cstring          | abstime                     | normal
 pg_catalog | abstimerecv | abstime          | internal                    | normal
 pg_catalog | abstimesend | bytea            | abstime                     | normal

發(fā)現(xiàn)更多寶藏

我在喜馬拉雅上分享聲音

《PostgreSQL數(shù)據(jù)庫(kù)內(nèi)核分析》刑赶,點(diǎn)開(kāi)鏈接可以聽(tīng)聽(tīng),有點(diǎn)意思懂衩。

《數(shù)據(jù)庫(kù)系統(tǒng)概論(第4版)》,點(diǎn)開(kāi)鏈接可以聽(tīng)聽(tīng)金踪,有點(diǎn)意思浊洞。

更多IT有聲課程,點(diǎn)我發(fā)現(xiàn)更多

第 0 課 PostgreSQL 系列文章列表

其他相關(guān)文章分享列表:

第 23 課 PostgreSQL 創(chuàng)建自己的數(shù)據(jù)庫(kù)胡岔、模式法希、用戶(hù)
第 22 課 PostgreSQL 控制文件
第 21 課 PostgreSQL 日志系統(tǒng)
第 16 課 查詢(xún)過(guò)程源碼分析
第 15 課 PostgreSQL 系統(tǒng)參數(shù)配置
第 14 課 PostgreSQL 數(shù)據(jù)存儲(chǔ)結(jié)構(gòu)
第 13 課 PostgreSQL 存儲(chǔ)之Page(頁(yè)面)源碼分析
第 12 課 PostgreSQL 認(rèn)證方式
第 11 課 PostgreSQL 增加一個(gè)內(nèi)核C函數(shù)
第 10 課 PostgreSQL 在內(nèi)核增加一個(gè)配置參數(shù)
第 09 課 PostgreSQL 4種進(jìn)程啟動(dòng)方式
第 08 課 PostgreSQL 事務(wù)介紹
第 07 課 PostgreSQL 數(shù)據(jù)庫(kù)、模式靶瘸、表苫亦、空間、用戶(hù)間的關(guān)系
第 06 課 PostgreSQL 系統(tǒng)表介紹
第 05 課 PostgreSQL 編譯源代碼進(jìn)行開(kāi)發(fā)
第 04 課 PostgreSQL 安裝最新的版本
第 03 課 PostgreSQL 代碼結(jié)構(gòu)
第 02 課 PostgreSQL 的特性怨咪、應(yīng)用屋剑、安裝
第 01 課 PostgreSQL 簡(jiǎn)介及發(fā)展歷程

上面文章都在專(zhuān)輯中:PostgreSQL專(zhuān)輯鏈接,點(diǎn)我查看

如果有用诗眨,可以收藏這篇文件唉匾,隨時(shí)在更新....

更多交流加群: PostgreSQL內(nèi)核開(kāi)發(fā)群 876673220

親,記得點(diǎn)贊匠楚、留言巍膘、打賞額!S蟛尽峡懈!

上一課
下一課

image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市与斤,隨后出現(xiàn)的幾起案子肪康,更是在濱河造成了極大的恐慌,老刑警劉巖幽告,帶你破解...
    沈念sama閱讀 217,406評(píng)論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件梅鹦,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡冗锁,警方通過(guò)查閱死者的電腦和手機(jī)齐唆,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,732評(píng)論 3 393
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)冻河,“玉大人箍邮,你說(shuō)我怎么就攤上這事茉帅。” “怎么了锭弊?”我有些...
    開(kāi)封第一講書(shū)人閱讀 163,711評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵堪澎,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我味滞,道長(zhǎng)樱蛤,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,380評(píng)論 1 293
  • 正文 為了忘掉前任剑鞍,我火速辦了婚禮昨凡,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘蚁署。我一直安慰自己便脊,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,432評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布光戈。 她就那樣靜靜地躺著哪痰,像睡著了一般。 火紅的嫁衣襯著肌膚如雪久妆。 梳的紋絲不亂的頭發(fā)上晌杰,一...
    開(kāi)封第一講書(shū)人閱讀 51,301評(píng)論 1 301
  • 那天,我揣著相機(jī)與錄音筷弦,去河邊找鬼乎莉。 笑死,一個(gè)胖子當(dāng)著我的面吹牛奸笤,可吹牛的內(nèi)容都是我干的惋啃。 我是一名探鬼主播,決...
    沈念sama閱讀 40,145評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼监右,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼边灭!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起健盒,我...
    開(kāi)封第一講書(shū)人閱讀 39,008評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤绒瘦,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后扣癣,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體惰帽,經(jīng)...
    沈念sama閱讀 45,443評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,649評(píng)論 3 334
  • 正文 我和宋清朗相戀三年父虑,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了该酗。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,795評(píng)論 1 347
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖呜魄,靈堂內(nèi)的尸體忽然破棺而出悔叽,到底是詐尸還是另有隱情,我是刑警寧澤爵嗅,帶...
    沈念sama閱讀 35,501評(píng)論 5 345
  • 正文 年R本政府宣布娇澎,位于F島的核電站,受9級(jí)特大地震影響睹晒,放射性物質(zhì)發(fā)生泄漏趟庄。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,119評(píng)論 3 328
  • 文/蒙蒙 一伪很、第九天 我趴在偏房一處隱蔽的房頂上張望岔激。 院中可真熱鬧,春花似錦是掰、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,731評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至匾七,卻和暖如春絮短,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背昨忆。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,865評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工丁频, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人邑贴。 一個(gè)月前我還...
    沈念sama閱讀 47,899評(píng)論 2 370
  • 正文 我出身青樓席里,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親拢驾。 傳聞我的和親對(duì)象是個(gè)殘疾皇子奖磁,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,724評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容