勁爆經典大帝國I(AWESOME CLASSIC MIX VOL.1)

2017/06/10

在Ubuntu Server上安裝Postgresql與pgunit

首先安裝postgresql
sudo apt-get install postgresql postgresql-contrib



安裝完後要裝pgunit, 在編譯之前先安裝下列項目
sudo apt-get install gcc

sudo apt-get install python-psycopg2
sudo apt-get install libpq-dev
ref: https://stackoverflow.com/questions/28253681/you-need-to-install-postgresql-server-dev-x-y-for-building-a-server-side-extensi

sudo apt-get install postgresql-server-dev-all
sudo apt-get install postgresql-common
ref: https://github.com/travis-ci/travis-ci/issues/2864

再來照pgunit官方文件輸入
sudo make PG_CONFIG=/usr/lib/postgresql/9.5/bin/pg_config
sudo make PG_CONFIG=/usr/lib/postgresql/9.5/bin/pg_config install

然後重啟postgresql
sudo service postgresql restart
or
sudo /etc/init.d/postgresql restart

接著建立extension
CREATE EXTENSION uint;

建立table
CREATE SEQUENCE rank_id_seq;
CREATE TABLE bar (
    a uint4 NOT NULL default nextval('rank_id_seq'),
    b text
);
ALTER SEQUENCE rank_id_seq owned by bar.a;
ref: https://stackoverflow.com/questions/3108777/how-to-auto-increment-in-postgresql

能auto increment的uint欄位就誕生啦!!!


沒有留言:

張貼留言

Related Posts Plugin for WordPress, Blogger...