第一步:su postgres
第二步:bash-4.2$ /usr/pgsql-9.1/bin/initdb -D /var/lib/pgsql/9.1/data/ , 斷行符號後出現如下資訊
The files belonging to this database system will be owned by user "postgres".
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".
fixing permissions on existing directory /var/lib/pgsql/9.1/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 24MB
creating configuration files ... ok
creating template1 database in /var/lib/pgsql/9.1/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.
Success. You can now start the database server using:
/usr/pgsql-9.1/bin/postgres -D /var/lib/pgsql/9.1/data
or
/usr/pgsql-9.1/bin/pg_ctl -D /var/lib/pgsql/9.1/data -l logfile start
第三步:用上邊兩個命令中的一個啟動服務
第四步:建立一個使用者(user)
bash-4.2$ createuser qiaoning -P
Enter password for new role: //輸入密碼
Enter it again: //再次輸入密碼
Shall the new role be a superuser? (y/n) n //是否是超級使用者,選否
Shall the new role be allowed to create databases? (y/n) y //該使用者是否可以建立資料庫,選是
Shall the new role be allowed to create more new roles? (y/n) n //該使用者是否可以建立新的角色,選否
第五步:建立資料庫
bash-4.2$ createdb qiaoning --owner=qiaoning //第一個qiaoning是資料庫名稱,第二個qiaoning是資料庫的擁有者
以上步驟完成後需要修改一些設定檔(主要是存取權限的設定)
第一步:進入剛才建立的database system所在的目錄,即:/var/lib/pgsql/9.1/data/