怎么在postgresql中使用initdb進行初始化-創(chuàng)新互聯(lián)

怎么在postgresql中使用initdb進行初始化?很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。

成都創(chuàng)新互聯(lián)專注于蠡縣網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供蠡縣營銷型網(wǎng)站建設(shè),蠡縣網(wǎng)站制作、蠡縣網(wǎng)頁設(shè)計、蠡縣網(wǎng)站官網(wǎng)定制、小程序開發(fā)服務(wù),打造蠡縣網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供蠡縣網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

initdb 官網(wǎng)

initdb創(chuàng)建了一個新的PostgreSQL數(shù)據(jù)庫集群。數(shù)據(jù)庫集群是由單個服務(wù)器實例管理的數(shù)據(jù)庫集合。

創(chuàng)建數(shù)據(jù)庫集群包括數(shù)據(jù)庫所在的目錄、生成共享目錄表(屬于整個集群而不是任何特定數(shù)據(jù)庫的表)以及創(chuàng)建template1和postgres數(shù)據(jù)庫。稍后創(chuàng)建新數(shù)據(jù)庫時,將復(fù)制template1數(shù)據(jù)庫中的所有內(nèi)容(因此,template1中安裝的任何內(nèi)容都會自動復(fù)制到以后創(chuàng)建的每個數(shù)據(jù)庫中。),postgres數(shù)據(jù)庫是供用戶、實例程序和第三方應(yīng)用程序使用的默認數(shù)據(jù)庫。

盡管initdb將嘗試創(chuàng)建指定的數(shù)據(jù)目錄,但如果所需數(shù)據(jù)目錄的父目錄是根目錄,則它可能沒有權(quán)限。要再這樣的設(shè)置中初始化,需要創(chuàng)建一個空數(shù)據(jù)目錄作為根目錄,然后使用chown將目錄的所有權(quán)分配給數(shù)據(jù)庫用戶賬戶,然后su成為運行initdb的數(shù)據(jù)庫用戶。

initdb必須作為擁有服務(wù)器進程的用戶運行,因為服務(wù)器需要訪問initdb創(chuàng)建的文件和目錄。由于服務(wù)器不能作為root用戶運行,所以也不能作為root用戶運行initdb。

出于安全原因,在默認情況下,initdb創(chuàng)建的新集群只能由集群所有者訪問?!猘llow-group-access選項允許與集群所有者屬于同一組的任何用戶讀取集群中的文件。這對于作為非特權(quán)用戶執(zhí)行備份非常有用。

initdb初始化數(shù)據(jù)庫集群的默認語言環(huán)境和字符集編碼。在創(chuàng)建數(shù)據(jù)庫時,可以分別設(shè)置字符集編碼、排序順序(LC_COLLATE)和字符集類(LC_CTYPE,例如upper、lower、digit)。initdb確定template1數(shù)據(jù)庫的那些設(shè)置,這些設(shè)置將作為所有其他數(shù)據(jù)庫的默認設(shè)置。

要更改默認的排序順序或字符集類,請使用——lc-collate和——lc-ctype選項。除了C或POSIX之外的排序順序也會造成性能損失。由于這些原因,在運行initdb時選擇正確的語言環(huán)境是很重要的。

其余的語言環(huán)境類別可以在服務(wù)器啟動后更改。還可以使用——locale設(shè)置所有語言環(huán)境類別的默認值,包括排序順序和字符集類。所有服務(wù)器語言環(huán)境值(lc_*)都可以通過SHOW All來顯示。

常用參數(shù):

-D directory/--pgdata=directory此選項指定應(yīng)該存儲數(shù)據(jù)庫集群的目錄。必傳。也可以設(shè)置環(huán)境變量PGDATA來替換-D選項。

-U username/--username=username選擇數(shù)據(jù)庫superuser的用戶名。這默認為運行initdb的用戶的名稱。

-E encoding/--encoding=encoding選擇模板數(shù)據(jù)庫的編碼。這也是您稍后創(chuàng)建的任何數(shù)據(jù)庫的默認編碼,

--lc-collate/--lc-ctype更改默認的排序順序或字符集類。

-k/--data-checksums在數(shù)據(jù)頁上使用校驗和來幫助檢測I/O系統(tǒng)的損壞,否則系統(tǒng)將是靜默的。啟用校驗和可能會導(dǎo)致顯著的性能損失。如果設(shè)置,則計算所有數(shù)據(jù)庫中所有對象的校驗和。所有校驗和失敗將在pg_stat_database視圖中報告。

所以postgresql初始化可能使用的命令是:

su - pguser001 -c "/u01/pgsql/bin/initdb --username=pguser001 --encoding=UTF8 --lc-collate=C --lc-ctype=en_US.
utf8 --data-checksums -D /data"

注:如果數(shù)據(jù)目錄已經(jīng)存在且初始化了的話,initdb將不會運行。

補充:postgresql 初始化 initdb 出現(xiàn)No such file or directory

1.initdb出現(xiàn)

 FATAL: could not open extension control file "/opt/HighGo/Develop/share/postgresql/extension/file_fdw.control": No such file or directory.

如下:

me@me:/opt/HighGo/Develop/bin$ <span >./initdb -D ../data -W</span>
The files belonging to this database system will be owned by user "me".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
creating directory ../data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 32MB
creating configuration files ... ok
creating template1 database in ../data/base/1 ... ok
initializing pg_authid ... ok
Enter new systemuser password: 
Enter it again: 
Enter syssao password: 
Enter it again: 
Enter syssso password: 
Enter it again: 
setting dba password ... ok
initializing dependencies ... ok
<span >creating system views ... FATAL: could not open extension control file "/opt/HighGo/Develop/share/postgresql/extension/file_fdw.control": No such file or directory
STATEMENT: /*</span>
 * PostgreSQL System Views
 *
 * Copyright (c) 1996-2012, PostgreSQL Global Development Group
 *
 * src/backend/catalog/system_views.sql

原因是file_fdw.control插件沒有安裝.進入源代碼目錄下的contrib目錄下.找到file_fdw文件進入其中,編譯安裝,

make
make install

同理出現(xiàn):

creating system views ... FATAL: 
could not open extension control file "/opt/HighGo/Develop/share/postgresql/extension/dblink.control": No such file or directory.

在contrib目錄下進入到dblink文件中,make,make install

所以如果出現(xiàn)一些其他的hstore.control 等.相應(yīng)的安裝上.

看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進一步的了解或閱讀更多相關(guān)文章,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,的支持。

網(wǎng)頁題目:怎么在postgresql中使用initdb進行初始化-創(chuàng)新互聯(lián)
網(wǎng)站鏈接:http://bm7419.com/article28/dsdpjp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、建站公司面包屑導(dǎo)航、企業(yè)網(wǎng)站制作網(wǎng)頁設(shè)計公司、網(wǎng)站設(shè)計

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)