主要參考資料
假定我們的兩台DB分別在不同機器
- Master 10.0.0.2
- Slave 10.0.0.3
postgres=> CREATE INDEX account_email_idx ON account (email); postgres=> \d account; Indexes: "account_pkey" PRIMARY KEY, btree (id) # Primary key預設就會建立index了 "account_email_idx" btree (email)
Composite indexes are used when two or more columns are best searched as a unit or if many queries reference only the columns specified in the index.我自己把它解釋成當一個query同時帶多個條件時,composite index可以加快查詢的速度。
All the columns in a composite index must be in the same table.
postgres=> CREATE INDEX account_composite_idx ON account (name, email); postgres=> \d account; Indexes: "account_pkey" PRIMARY KEY, btree (id) "account_composite_idx" btree (name, email)
postgres=> VACUUM VERBOSE ANALYZE;
# Start su postgres -c "/usr/local/pgsql/bin/pg_ctl start -D /usr/local/pgsql/data" # Stop su postgres -c "/usr/local/pgsql/bin/pg_ctl stop -D /usr/local/pgsql/data" # restart su postgres -c "/usr/local/pgsql/bin/pg_ctl restart -D /usr/local/pgsql/data" # Init postgres sudo mkdir /usr/local/pgsql/data chown postgres:postgres /usr/local/pgsql/data su postgres -c "/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data" # Create user /usr/local/pgsql/bin/createuser -U postgres -P userA # Drop user /usr/local/pgsql/bin/dropuser -U postgres userA # Create db /usr/local/pgsql/bin/createdb -O userA -U postgres testdb # Drop db /usr/local/pgsql/bin/dropdb -U postgres testdb # Dump db /usr/local/pgsql/bin/pg_dump -U postgres testdb > dump.sql # Restore db /usr/local/pgsql/bin/psql -U postgres -d testdb < dump.sql # Grant all privileges /usr/local/pgsql/bin/psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE testdb TO userA;" # Enter postgresql command line /usr/local/pgsql/bin/psql -U postgres -d poesgres -h localhost -p 5432
listen_addresses = '192.168.0.3' # 設定listen IP
host all all 127.0.0.1/32 trust host all all 192.168.0.0/16 trust host all all 10.10.1.5/32 password
pgbench -U postgres -i -s 50 postgres pgbench -U postgres -c 100 -t 100 -S postgres
def D1(fn): def newFn(): return "" + fn() + "" return newFn @D1 def f1(): return "a sentence" print f1()
# 搜尋套件 port list | grep python # 安裝python主程式 sudo port install python26 # 安裝 easy_install sudo port install py26-setuptools #之後就可以利用easy_install去安裝更多python套件了