Recent Comments

This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

顯示具有 postgresql 標籤的文章。 顯示所有文章
顯示具有 postgresql 標籤的文章。 顯示所有文章

2013年12月20日 星期五

PostgreSQL 安裝 pldebugger USE_PGSX

PostgreSQL 安裝 pldebugger USE_PGSX

使用 USE_PGSX=1 make,在pldebugger編好後就會直接把編好的plugin_debugger.so和pldbgapi--1.0.sql放到/usr/pgsql-9.3相對應的位置。

yum install git readline-devel zlib-devel openssl-devel

cd /opt
tar xvzf postgresql-9.3.2.tar.gz

cd /opt/postgresql-9.3.2
USE_PGXS=1 ./configure
USE_PGXS=1 make

cd /opt/postgresql-9.3.2/contrib/
git clone git://git.postgresql.org/git/pldebugger.git
make 

cd /opt/postgresql-9.3.2/contrib/pldebugger
USE_PGXS=1 make
USE_PGXS=1 make install

[root@localhost pldebugger]# USE_PGXS=1 make install                                                                                                         gcc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -I/usr/include/et -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fpic -shared -o plugin_debugger.so plpgsql_debugger.o plugin_debugger.o dbgcomm.o pldbgapi.o -L/usr/pgsql-9.3/lib -L/usr/lib64 -Wl,--as-needed
/bin/mkdir -p '/usr/pgsql-9.3/lib'
/bin/mkdir -p '/usr/pgsql-9.3/share/extension'
/bin/mkdir -p '/usr/pgsql-9.3/share/extension'
/bin/mkdir -p '/usr/share/doc/pgsql/extension'
/usr/bin/install -c -m 755  plugin_debugger.so '/usr/pgsql-9.3/lib/plugin_debugger.so'
/usr/bin/install -c -m 644 ./pldbgapi.control '/usr/pgsql-9.3/share/extension/'
/usr/bin/install -c -m 644 ./pldbgapi--1.0.sql ./pldbgapi--unpackaged--1.0.sql  '/usr/pgsql-9.3/share/extension/'
/usr/bin/install -c -m 644 ./README.pldebugger '/usr/share/doc/pgsql/extension/'


vim /var/lib/pgsql/9.3/data/postgresql.conf
加入下面的設定
shared_preload_libraries = '$libdir/plugin_debugger'

重新啟動
service postgresql-9.3 restart

安裝pldbgapi
su - postgres
psql
CREATE EXTENSION pldbgapi;
\dx

-bash-4.1$ psql
psql (9.3.2)
Type "help" for help.

postgres=# CREATE EXTENSION pldbgapi;
CREATE EXTENSION
postgres=# \dx
                              List of installed extensions
   Name    | Version |   Schema   |                     Description
-----------+---------+------------+------------------------------------------------------
adminpack | 1.0     | pg_catalog | administrative functions for PostgreSQL
pldbgapi  | 1.0     | public     | server-side support for debugging PL/pgSQL functions
plpgsql   | 1.0     | pg_catalog | PL/pgSQL procedural language
(3 rows)

================================================================
當pldebugger在USE_PGXS=1 make時出現下面的錯誤要安裝 openssl-devel套件,安裝好後再重新執行USE_PGXS=1 make

[root@localhost pldebugger]# USE_PGXS=1 make
gcc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -I/usr/include/et -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fpic -I. -I. -I/usr/pgsql-9.3/include/server -I/usr/pgsql-9.3/include/internal -I/usr/include/et -D_GNU_SOURCE -I/usr/include/libxml2  -I/usr/include  -c -o pldbgapi.o pldbgapi.c
In file included from pldbgapi.c:98:
/usr/pgsql-9.3/include/server/libpq/libpq-be.h:25:25: error: openssl/ssl.h: No such file or directory
/usr/pgsql-9.3/include/server/libpq/libpq-be.h:26:25: error: openssl/err.h: No such file or directory
/usr/pgsql-9.3/include/server/libpq/libpq-be.h:36:27: error: gssapi/gssapi.h: No such file or directory
In file included from pldbgapi.c:98:
/usr/pgsql-9.3/include/server/libpq/libpq-be.h:86: error: expected specifier-qualifier-list before ‘gss_buffer_desc’
/usr/pgsql-9.3/include/server/libpq/libpq-be.h:176: error: expected specifier-qualifier-list before ‘SSL’
make: *** [pldbgapi.o] Error 1

PL/SQL 和 PL/pgSQL 旅行時間TRIGGER

以下TRIGGER內容主要是當區段旅行時間比對成功後,在INSERT AVI_SECTION_TRAVEL資料表後會執行下面的TRIGGER,將新的旅行時間更新到XML_AVI_VALUE表中,因為資料的時間需要是每五分鐘的顯示,如5分、10分,N_MIN_FIND就是找出現在旅行時間是在那個五分鐘區間中,如旅行時間是20131221 12:12:30,則 N_MIN_FIND會是20131221 12:15:00

以下是ORACLE和POSTGRESQL的寫法,主要差異在N_MIN_MOD和N_MIN_FIND兩個變數

ORACLE
=====================================================================
DECLARE
C_MIN_LOG_RANGE CONSTANT INTEGER := 5; --統計分鐘數
  N_MIN_MOD INTEGER;       --取餘數
  N_MIN_ADD INTEGER;       --以旅行時間要加的分鐘數 (統計分鐘數 - N_MIN_MOD)
  N_MIN_FIND TIMESTAMP;    --找volume記錄時間  = 旅行時間 + N_MIN_ADD
N_RECORD_COUNT INTEGER;
BEGIN
N_MIN_MOD := MOD(TO_CHAR(:NEW.DATETIME,'MI'),C_MIN_LOG_RANGE);
  N_MIN_ADD := C_MIN_LOG_RANGE-N_MIN_MOD;
  N_MIN_FIND := TO_TIMESTAMP(TO_CHAR(:NEW.DATETIME+(N_MIN_ADD/1440),'YYYY-MM-DD HH24:MI'),'YYYY-MM-DD HH24:MI');

SELECT COUNT(SECTION_ID) INTO N_RECORD_COUNT FROM XML_AVI_VALUE WHERE SECTION_ID=:NEW.SECTION_ID;

IF N_RECORD_COUNT>0 THEN
UPDATE XML_AVI_VALUE SET TRAVELTIME=:NEW.TRAVEL_SMOOTH,DATACOLLECTTIME=N_MIN_FIND  WHERE SECTION_ID=:NEW.SECTION_ID;
END IF;
END;


POSTGRESQL
=====================================================================
DECLARE
C_MIN_LOG_RANGE CONSTANT INTEGER := 5; --統計分鐘數
N_MIN_MOD INTEGER;       --取餘數
N_MIN_ADD INTEGER;       --以旅行時間要加的分鐘數 (統計分鐘數 - N_MIN_MOD)
N_MIN_FIND TIMESTAMP;     --找volume記錄時間  = 旅行時間 + N_MIN_ADD
N_RECORD_COUNT INTEGER; --找出XML_AVI_VALUE資料表中是否有該SECTION_ID的資料
BEGIN--

--insert avi_xml_value
        N_MIN_MOD := MOD(to_number(TO_CHAR(NEW.datetime,'MI'),'99'),C_MIN_LOG_RANGE);
        IF N_MIN_MOD=0 THEN
   N_MIN_ADD := 0;
ELSE
   N_MIN_ADD := C_MIN_LOG_RANGE-N_MIN_MOD;
END IF;

N_MIN_FIND := TO_TIMESTAMP(TO_CHAR(NEW.datetime,'YYYY-MM-DD HH24:MI'),'YYYY-MM-DD HH24:MI')+(TO_TIMESTAMP(TO_CHAR(N_MIN_ADD,'99'),'MI')-TO_TIMESTAMP(TO_CHAR(0,'99'),'MI'));

SELECT COUNT(SECTION_ID) INTO N_RECORD_COUNT FROM XML_AVI_VALUE WHERE SECTION_ID=NEW.SECTION_ID;

IF N_RECORD_COUNT>0 THEN
   UPDATE XML_AVI_VALUE SET TRAVELTIME=NEW.TRAVEL_SMOOTH,DATACOLLECTTIME=N_MIN_FIND  WHERE SECTION_ID=NEW.SECTION_ID;
END IF;
END;

PostgreSQL 安裝 pldebugger

yum install git readline-devel zlib-devel

cd /opt
tar xvzf postgresql-9.3.2.tar.gz
cd /opt/postgresql-9.3.2/contrib/
git clone git://git.postgresql.org/git/pldebugger.git

cd /opt/postgresql-9.3.2
./configure
make

cd /opt/postgresql-9.3.2/contrib/pldebugger
make
make install

/bin/mkdir -p '/usr/local/pgsql/lib'
/bin/mkdir -p '/usr/local/pgsql/share/extension'
/bin/mkdir -p '/usr/local/pgsql/share/extension'
/bin/mkdir -p '/usr/local/pgsql/share/doc//extension'
/usr/bin/install -c -m 755  plugin_debugger.so '/usr/local/pgsql/lib/plugin_debugger.so'
/usr/bin/install -c -m 644 ./pldbgapi.control '/usr/local/pgsql/share/extension/'
/usr/bin/install -c -m 644 ./pldbgapi--1.0.sql ./pldbgapi--unpackaged--1.0.sql  '/usr/local/pgsql/share/extension/'
/usr/bin/install -c -m 644 ./README.pldebugger '/usr/local/pgsql/share/doc//extension/'

cp /usr/local/pgsql/lib/plugin_debugger.so /usr/pgsql-9.3/lib/  
cp /usr/local/pgsql/share/extension/pldbgapi--1.0.sql /usr/pgsql-9.3/share/extension/  
cp /usr/local/pgsql/share/extension/pldbgapi--unpackaged--1.0.sql /usr/pgsql-9.3/share/extension/
cp /usr/local/pgsql/share/extension/pldbgapi.control /usr/pgsql-9.3/share/extension/

vim /var/lib/pgsql/9.3/data/postgresql.conf
加入
shared_preload_libraries = '$libdir/plugin_debugger'

service postgresql-9.3 restart

su - postgres
psql
CREATE EXTENSION pldbgapi;
\dx

-bash-4.1$ psql
psql (9.3.2)
Type "help" for help.

postgres=# CREATE EXTENSION pldbgapi;
CREATE EXTENSION
postgres=# \dx
                              List of installed extensions
   Name    | Version |   Schema   |                     Description
-----------+---------+------------+------------------------------------------------------
adminpack | 1.0     | pg_catalog | administrative functions for PostgreSQL
pldbgapi  | 1.0     | public     | server-side support for debugging PL/pgSQL functions
plpgsql   | 1.0     | pg_catalog | PL/pgSQL procedural language
(3 rows)

postgres=#

2012年6月7日 星期四

the log_filename parameter must equal

當執行pgadmin III的工具->伺服器狀態時會出現the log_filename parameter must equal……
主要是設定檔的LOG FILE格式和PGADMIN III的格式不符所造成的

修改postgresql.conf
vim /var/lib/pgsql/9.1/data/postgresql.conf
修改下面log_filename的參數內容
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'

安裝adminpack


使用locate adminpack找到檔案路徑
/usr/pgsql-9.1/share/extension/adminpack--1.0.sql


執行
su -l postgres
psql -d n5_data < /usr/pgsql-9.1/share/extension/adminpack--1.0.sql


出現Use "CREATE EXTENSION adminpack" to load this file.
在9.1的安裝方式改了,改用下面的指令,直接到資料庫中執行指令產生


psql -d n5_data 
CREATE EXTENSION adminpack


最後reload設定檔
su -l postgres
 /usr/pgsql-9.1/bin/pg_ctl reload -d /var/lib/pgsql/9.1/data/

重新開始後pgadmin iii就不會出現這個錯誤,也可以用pgadmin直接看到log內容
log檔案位置:/var/lib/pgsql/9.1/data/pg_log

2012年5月4日 星期五

postgresql install pgagent工作排程

yum install pgagent_91

su -l postgres
psql < /usr/share/pgagent_91-3.0.1/pgagent.sql

在PgAdminIII下就會出現Job的功能!

postgresql 備份和還原

備份
pg_dump dbname | gzip > filename.gz


還原前先建立
tablespace
資料庫使用者
資料庫


還原
gunzip -c filename.gz | psql dbname

2012年5月2日 星期三

Server instrumentation not install

安裝完postgresql後,用PgAdminIII連線會出現Server instrumentation not install的視窗

解決方法:
yum install postgresql91-contrib
su - postgres
psql < /usr/pgsql-9.1/share/extension/adminpack--1.0.sql
再用PgAdminIII重新連線一次,點選在 Server instrumentation not install的視窗下方的『Fix it!』按鈕

2012年4月16日 星期一

phpPgAdmin You don't have permission to access /phpPgAdmin on this server.

安裝完phpPgAdmin後
192.168.1.XXX/phpPgAdmin會出現You don't have permission to access /phpPgAdmin on this server.
但在127.0.0.1/phpPgAdmin或localhost/phpPgAdmin都可以連上

解決方式:
設定vim /etc/httpd/conf.d/phpPgAdmin.conf
刪除Allow from 127.0.0.1
增加allow from all
重啟httpd

==================================

Alias /phpPgAdmin /usr/share/phpPgAdmin


    Order deny,allow
    Deny from all
#    Allow from 127.0.0.1
    allow from all
    Allow from ::1
    # Allow from .example.com


2011年7月3日 星期日

password authentication failed for user "postgres"

postgresql安裝好後用pgadmin連接出現如下的錯誤訊息:

Error connecting to the server:FATAL: password authentication failed for user "postgres"  

錯誤原因是沒有設定postgres的密碼,檢查及設定如下:
[root@Vigor14 ~]# su -l postgres -bash-3.2$ psql psql (8.4.7) Type "help" for help.  postgres=# select * from pg_shadow;  usename  | usesysid | usecreatedb | usesuper | usecatupd | passwd | valunti l | useconfig  ----------+----------+-------------+----------+-----------+--------+-------- --+-----------  postgres |       10 | t           | t        | t         |        |           |  (1 row)  postgres=# alter user postgres with password 'postgres'; ALTER ROLE postgres=#  

安裝ora2pg

安裝ora2pg

  • 安裝 perl-DBD-Pg
    yum install perl-DBD-Pg
  • 安裝ora2pg
    tar -xvf ora2pg-8.4.tar.bz2
    cd ora2pg-8.4
    perl Makefile.PL
    make
    make install
  • 執行 ora2pg -h
    若出現下列的結果請先安裝『perl-DBD-Pg』套件
    [root@DB ora2pg-8.4]# ora2pg
    Can't locate DBD/Pg.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /usr/lib/perl5/site_perl/5.8.8/Ora2Pg.pm line 921.
    BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.8/Ora2Pg.pm line 921.
    Compilation failed in require at /usr/local/bin/ora2pg line 27.
    BEGIN failed--compilation aborted at /usr/local/bin/ora2pg line 27.
  • 設定ora2pg
    vim /etc/ora2pg/ora2pg.conf
    資料庫連接修改內容如下:
    ORACLE_HOME /opt/oracle/product/10.2.0/db_1
    ORACLE_DSN dbi:Oracle:host=localhsot;sid=hccg
    ORACLE_USER hccg
    ORACLE_PWD xxxxx

安裝 DBD-Oracle

安裝 DBD-Oracle
  • 設定參數
    export ORACLE_HOME=/opt/oracle/product/10.2.0/db_1
    export LD_LIBRARY_PATH=/opt/oracle/product/10.2.0/db_1/lib32
    ln -s /opt/oracle/product/10.2.0/db_1/lib /opt/oracle/product/10.2.0/db_1/lib32
    ln -s /opt/oracle/product/10.2.0/db_1/rdbms/lib /opt/oracle/product/10.2.0/db_1/rdbms/lib32
  • 安裝
    tar -xvzf DBD-Oracle-1.28.tar.gz
    cd DBD-Oracle-1.28
    perl Makefile.PL
    make
    make install

安裝postgresql資料庫

安裝postgresql資料庫
  • 安裝資料庫postgresql84
    yum install postgresql84 postgresql84-server postgresql84-libs
  • 第一次執行需要初始化資料庫
    service postgresql initdb
  • 啟動資料庫
    service postgresql start
  • postgresql設定開機時啟動
    chkconfig postgresql on
  • 修改/var/lib/pgsql/data/pg_hba.conf
    host all all 127.0.0.1/32 md5
    host all all 192.168.1.0/24 md5
  • 修改/var/lib/pgsql/data/postgresql.conf
    listen_addresses = '*'
  • 重新載入設定
    su -l postgres
    pg_ctl reload