1. 打開(kāi)官網(wǎng)
2. 點(diǎn)擊download
3. 選擇版本類(lèi)型
根據(jù)實(shí)際情況選擇你的目標(biāo)主機(jī)類(lèi)型速勇,我的是Centos锚扎,所以選擇Red Hat.
4. 選擇系統(tǒng)配置
選擇后會(huì)生成對(duì)對(duì)應(yīng)的rpm URL地址。
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
安裝服務(wù)器端:
yum install postgresql10-server
7. 啟動(dòng)postgresql
初始化啟動(dòng)數(shù)據(jù)庫(kù)
/usr/pgsql-10/bin/postgresql-10-setup initdb
初始化成功后:數(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
查看進(jìn)程:
ps -ef|grep postgres
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)更多
其他相關(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蟛尽峡懈!