mac電腦os x EI Capitan系統下解壓版postgreSQL使用


       最近沒事研究postgreSQL和學習python3,於是在自己的mac電腦上試驗了一下postgreSQL的使用。由於不想用安裝版的postgreSQL版本,所以直接使用了解壓版的postgreSQL版本(下載地址https://www.enterprisedb.com/download-postgresql-binaries )。下載到zip包后直接解壓,目錄結構如下:


這里也就懶得設置什么環境變量了,直接開始干吧。

先進入bin目錄下,執行initdb文件,如下:

YZQ-MacBook-Pro:bin yinzeqiang$ ./initdb  -D /Users/yinzeqiang/softDev/pgsql/dataFiles/ -E utf8
The files belonging to this database system will be owned by user "yinzeqiang".
This user must also own the server process.

The database cluster will be initialized with locale "zh_CN.UTF-8".
initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
The default text search configuration will be set to "simple".

Data page checksums are disabled.

fixing permissions on existing directory /Users/yinzeqiang/softDev/pgsql/dataFiles ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
creating template1 database in /Users/yinzeqiang/softDev/pgsql/dataFiles/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
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:


1.initdb命令

./initdb  -D /Users/yinzeqiang/softDev/pgsql/dataFiles/ -E utf8  命令,我的理解就是搞一個數據文件存儲目錄初始化數據庫吧。-D后跟數據庫數據文件存儲路徑,-E后跟編碼。

2.pg_ct命令

pg_ct命令可以開始數據庫服務或者關閉數據庫。

./pg_ctl -D /Users/yinzeqiang/softDev/pgsql/dataFiles/ -l /Users/yinzeqiang/softDev/pgsql/dataFiles/postgrepsql.log  start命令,開始數據庫服務。-D后跟數據庫數據文件存儲

徑,-l后跟日志文件地址。

./pg_ctl stop -w -D /Users/yinzeqiang/softDev/pgsql/dataFiles/ -m smart命令結束數據庫服務。-D后跟數據庫數據文件存儲路徑.-m后跟數據庫停止或者重啟的模式:

一共有三種模式:

  smart       quit after all clients have disconnected

  fast        quit directly, with proper shutdown

  immediate   quit without complete shutdown; will lead to recovery on restart

3.createdb和createuser命令


YZQ-MacBook-Pro:bin yinzeqiang$ ./createuser -a -d -e -P python3learner
Enter password for new role:
Enter it again:
CREATE ROLE python3learner PASSWORD 'md5fb444479c9daa2b26fa4d6c045699070' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;
   

createuser命令創建用戶,用法:createuser [OPTION]... [ROLENAME]

OPTION可用參數如下:

    [-a]:允許創建其他用戶,相當於創建一個超級用戶;
    [-A]:不允許此用戶創建其他用戶;
    [-d]:允許此用戶創建數據庫;
    [-D]:不允許此用戶創建數據庫;
    [-e]:將執行過程顯示到Shell上;
    [-P]:創建用戶時,同時設置密碼;
    [-h 主機名]:為某個主機上的Postgres創建用戶;
    [-p port]:與-h參數一同使用,指定主機的端口。

createdb命令用於創建數據庫,用法:createdb [OPTION]... [DBNAME] [DESCRIPTION]。如下:


./createdb -E utf8 testdb  創建名為testdb的數據庫,-E后跟數據庫編碼


4.psql命令

psql可以連接數據庫,如下:

YZQ-MacBook-Pro:dataFiles yinzeqiang$ psql -d testdb
psql (9.5.5)
Type "help" for help.

testdb=# \d
List of relations
Schema | Name | Type | Owner
--------+-----------------------------------+----------+----------------
public | auth_group | table | python3learner
public | auth_group_id_seq | sequence | python3learner
public | auth_group_permissions | table | python3learner
public | auth_group_permissions_id_seq | sequence | python3learner
public | auth_permission | table | python3learner

psql -d testdb連接到testdb數據庫。

5.所有命令可以通過 '命令 --help'的形式查看用法,稍微懂一點英語都可以看懂

(IT菜鳥,有錯誤請指正)


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com