initdb 官網
initdb創(chuàng)建了一個新的PostgreSQL數(shù)據庫集群。數(shù)據庫集群是由單個服務器實例管理的數(shù)據庫集合。
創(chuàng)建數(shù)據庫集群包括數(shù)據庫所在的目錄、生成共享目錄表(屬于整個集群而不是任何特定數(shù)據庫的表)以及創(chuàng)建template1和postgres數(shù)據庫。稍后創(chuàng)建新數(shù)據庫時,將復制template1數(shù)據庫中的所有內容(因此,template1中安裝的任何內容都會自動復制到以后創(chuàng)建的每個數(shù)據庫中。),postgres數(shù)據庫是供用戶、實例程序和第三方應用程序使用的默認數(shù)據庫。
盡管initdb將嘗試創(chuàng)建指定的數(shù)據目錄,但如果所需數(shù)據目錄的父目錄是根目錄,則它可能沒有權限。要再這樣的設置中初始化,需要創(chuàng)建一個空數(shù)據目錄作為根目錄,然后使用chown將目錄的所有權分配給數(shù)據庫用戶賬戶,然后su成為運行initdb的數(shù)據庫用戶。
initdb必須作為擁有服務器進程的用戶運行,因為服務器需要訪問initdb創(chuàng)建的文件和目錄。由于服務器不能作為root用戶運行,所以也不能作為root用戶運行initdb。
出于安全原因,在默認情況下,initdb創(chuàng)建的新集群只能由集群所有者訪問。——allow-group-access選項允許與集群所有者屬于同一組的任何用戶讀取集群中的文件。這對于作為非特權用戶執(zhí)行備份非常有用。
initdb初始化數(shù)據庫集群的默認語言環(huán)境和字符集編碼。在創(chuàng)建數(shù)據庫時,可以分別設置字符集編碼、排序順序(LC_COLLATE)和字符集類(LC_CTYPE,例如upper、lower、digit)。initdb確定template1數(shù)據庫的那些設置,這些設置將作為所有其他數(shù)據庫的默認設置。
要更改默認的排序順序或字符集類,請使用——lc-collate和——lc-ctype選項。除了C或POSIX之外的排序順序也會造成性能損失。由于這些原因,在運行initdb時選擇正確的語言環(huán)境是很重要的。
其余的語言環(huán)境類別可以在服務器啟動后更改。還可以使用——locale設置所有語言環(huán)境類別的默認值,包括排序順序和字符集類。所有服務器語言環(huán)境值(lc_*)都可以通過SHOW All來顯示。
常用參數(shù):
-D directory/--pgdata=directory此選項指定應該存儲數(shù)據庫集群的目錄。必傳。也可以設置環(huán)境變量PGDATA來替換-D選項。
-U username/--username=username選擇數(shù)據庫superuser的用戶名。這默認為運行initdb的用戶的名稱。
-E encoding/--encoding=encoding選擇模板數(shù)據庫的編碼。這也是您稍后創(chuàng)建的任何數(shù)據庫的默認編碼,
--lc-collate/--lc-ctype更改默認的排序順序或字符集類。
-k/--data-checksums在數(shù)據頁上使用校驗和來幫助檢測I/O系統(tǒng)的損壞,否則系統(tǒng)將是靜默的。啟用校驗和可能會導致顯著的性能損失。如果設置,則計算所有數(shù)據庫中所有對象的校驗和。所有校驗和失敗將在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ù)據目錄已經存在且初始化了的話,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 style="color:rgb(51,51,255);">./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 style="color:rgb(204,0,0);">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文件進入其中,編譯安裝,
同理出現(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 等.相應的安裝上.
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。
您可能感興趣的文章:- postgresql 利用xlog進行熱備操作
- Postgresql中xlog生成和清理邏輯操作
- Postgresql去重函數(shù)distinct的用法說明
- postgresql 12版本搭建及主備部署操作
- 開源數(shù)據庫postgreSQL13在麒麟v10sp1源碼安裝過程詳解
- postgresql 如何查看pg_wal目錄下xlog文件總大小
- postgresql之使用lsn 獲取 wal文件名的實例
- PostgreSQL 實現(xiàn)定時job執(zhí)行(pgAgent)