wget
tar xvfz libpqxx-4.0.tar.gz
cd libpqxx-4.0
./configure
make
make install
shell
可以啟動/重新啟動postgres伺服器,使用以下命令執行:
[postgres@localhost documents]$ pg_ctl -d /home/my_softwares/postgresql/data -l logfile restart
以下c
**段顯示如何連線到埠5432
上本地機器上執行的現有資料庫。在這裡,使用反斜槓\
續行。
// test.cpp
#include #include using namespace std;
using namespace pqxx;
int main(int argc, char* argv)
else
c.disconnect ();
}catch (const std::exception &e)
}
現在,我們編譯並執行上面的程式來連線到資料庫postgres
,它已經在你的架構中可用,可以使用使用者postgres
和密碼為:123進行訪問。 您可以根據資料庫設定使用使用者名稱和密碼。記住保持-lpqxx
和-lpq
在給定的順序! 否則,鏈結器將抱怨關於缺少以「pq
」開頭的名稱的函式。
[root@localhost documents]# g++ test.cpp -lpqxx -lpq -o test
/usr/bin/ld: cannot find -lpq
collect2: error: ld returned 1 exit status
[root@localhost documents]#
[root@localhost documents]# g++ $(pkg-config --libs libpqxx) test.cpp -lpqxx -lpq -o test
package libpqxx was not found in the pkg-config search path.
perhaps you should add the directory containing `libpqxx.pc'
to the pkg_config_path environment variable
no package 'libpqxx' found
/usr/bin/ld: cannot find -lpq
collect2: error: ld returned 1 exit status
[root@localhost documents]#
[root@localhost documents]# find / -name libpqxx.pc
/home/zlf/downloads/libpqxx-4.0/libpqxx.pc
find: 『/run/user/1000/gvfs』: permission denied
/usr/local/lib/pkgconfig/libpqxx.pc
[root@localhost documents]#
[root@localhost documents]# export pkg_config_path=/usr/local/lib/pkgconfig:$pkg_config_path
[root@localhost documents]#
[root@localhost documents]# g++ $(pkg-config --libs libpqxx) test.cpp -lpqxx -lpq -o test
[root@localhost documents]#
[root@localhost documents]# dir
creategroupuser.txt environment_variables.txt postgrelsql_install.txt setpasswd.txt test test.cpp
[root@localhost documents]# ./test
./test: error while loading shared libraries: libpq.so.5: cannot open shared object file: no such file or directory
[root@localhost documents]#
[root@localhost documents]# export ld_library_path=/home/my_softwares/postgresql/install/lib:$ld_library_path
[root@localhost documents]#
[root@localhost documents]# ./test
could not connect to server: connection refused
is the server running on host "127.0.0.1" and accepting
tcp/ip connections on port 5432?
[root@localhost documents]# pg_ctl -d /home/my_softwares/postgresql/data -l logfile start
bash: pg_ctl: command not found...
[root@localhost documents]#
[root@localhost documents]# $path
bash: /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin: no such file or directory
[root@localhost documents]#
[root@localhost documents]# source /etc/profile
[root@localhost documents]#
[root@localhost documents]# $path
bash: /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/my_softwares/postgresql/install/bin: no such file or directory
[root@localhost documents]#
[root@localhost documents]# pg_ctl -d /home/my_softwares/postgresql/data -l logfile start
pg_ctl: cannot be run as root
please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.
[root@localhost documents]#
[root@localhost documents]# su postgres
[postgres@localhost documents]$
[postgres@localhost documents]$ pg_ctl -d /home/my_softwares/postgresql/data -l logfile start
could not change directory to "/home/zlf/documents": permission denied
waiting for server to start.... done
server started
[postgres@localhost documents]$
[postgres@localhost documents]$ ./test
opened database successfully: postgres
[postgres@localhost documents]$
[postgres@localhost documents]$
參考:
使用安全SSL連線PostgreSQL資料庫
2020年4月8日15 29 47 今天主要是在postgresql資料庫上面遇到的乙個要求 配置ssl方式連線資料庫,連線後檢視版本正確。ssl 的英文全稱是 secure sockets layer 中文名為 安全套接層協議層 它是網景 netscape 公司提出的基於 web 應用的安全協議。...
PostgreSQL連線問題
近日用postgresql和npgsql寫過程式,由於客戶數量有300多個,所以有的就連線不上了。調整了max connection為500,問題是解決了,可是記憶體使用也是猛漲。差了點資料,估計可通過兩個方面解決一下問題 postgresql的連線池,如pgbouncer 解決方法 1 在連線字串...
QT連線PostgreSQL步驟
1.編譯驅動 其次 在qt的src plugins sqldriver psql目錄下修改psql.pro,加入 includepath d postgresql 9.2 include libs d postgresql 9.2 lib libpq.lib 將postgresql對應的目錄加入 最...