如何在ubuntu上去更新postgresql

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在ubuntu上去更新postgresql相关的知识,希望对你有一定的参考价值。

安装组件
客户端安装
sudo apt-get install postgresql-client
服务器安装

sudo apt-get install postgresql postgresql-contrib

获取Installing PostGIS, procedural languages, client interfaces等插件列表

apt-cache search postgres

Ruby PG gem安装,需要生成Native Extension
首先安装相应package

sudo apt-get install libpq-dev

找到pg_config所在位置

sudo find / -name pg_config

安装pg gem

gem install pg -- --with-pg-config=/usr/bin/pg_config

服务器配置
设置postgres用户,用postgres用户登录并修改密码

sudo -u postgres psql postgres

为postgres用户设置密码

\password postgres

创建新数据库
sudo -u postgres createdb mydb

服务器高级设置
创建用户
sudo -u postgres createuser --superuser $USER
sudo -u postgres psql
postgres=# \password $USER

管理用户及权限
编辑/etc/postgresql/current/main/postgresql.conf文件用以监听其它网络
listen_addresses = '*'

创建新用户tesdb及该用户所拥有的数据库testdb
sudo -u postgres createuser -D -A -P testdb

sudo -u postgres createdb -O testdb testdb

编辑/etc/postgresql/current/main/pg_hba.conf文件,允许testdb用户远程连接testdb数据库
host testdb testdb 0.0.0.0/0 md5

重新加载配置
sudo /etc/init.d/postgresql reload

重启数据库
sudo /etc/init.d/postgresql restart
参考技术A sudo apt-get update

如何在 ubuntu 中获取 Qt PostgreSQL 插件?

【中文标题】如何在 ubuntu 中获取 Qt PostgreSQL 插件?【英文标题】:How get the Qt PostgreSQL plugin in ubuntu? 【发布时间】:2021-01-04 15:42:54 【问题描述】:

美好的一天。 我写了一个小程序来了解 Qt c++ 和 SQL 是如何工作的。 她给我写信:

QSqlQuery::exec: database not open
QSqlError("", "Driver not loaded", "Driver not loaded")
("QSQLITE", "QODBC", "QODBC3", "QPSQL", "QPSQL7")

上网后发现需要一个SQL插件,找到了这个指令https://doc.qt.io/qt-5/sql-driver.html#qpsql(为什么插件开箱不工作?没关系。) 行。我转到文件夹 ~/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers 执行“qmake -- PSQL_INCDIR=/usr/include/pgsql” 好的

Running configuration tests...
Done running configuration tests.

Configure summary:

Qt Sql Drivers:
  DB2 (IBM) .............................. no
  InterBase .............................. no
  MySql .................................. no
  OCI (Oracle) ........................... no
  ODBC ................................... no
  PostgreSQL ............................. yes
  SQLite2 ................................ no
  SQLite ................................. yes
    Using system provided SQLite ......... no
  TDS (Sybase) ........................... no

Qt is now configured for building. Just run 'make'.
Once everything is built, you must run 'make install'.
Qt will be installed into '/usr'.

Prior to reconfiguration, make sure you remove any leftovers from
the previous build.

做“制作子psql” 我得到了

cd psql/ && ( test -e Makefile || /usr/lib/qt5/bin/qmake -o Makefile /home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql/psql.pro PSQL_INCDIR=/usr/include/pgsql ) && make -f Makefile
make[1]: вход в каталог «/home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql»
g++ -c -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -O2 -std=c++1z -fvisibility=hidden -fvisibility-inlines-hidden -fno-exceptions -Wall -W -Wvla -Wdate-time -Wshift-overflow=2 -Wduplicated-cond -Wno-stringop-overflow -Wno-deprecated-copy -Wno-redundant-move -Wno-format-overflow -Wno-init-list-lifetime -D_REENTRANT -fPIC -DQT_NO_JAVA_STYLE_ITERATORS -DQT_DEPRECATED_WARNINGS -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_EXCEPTIONS -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_NO_DEBUG -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -I. -isystem /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8 -isystem /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore/5.12.8 -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore/5.12.8/QtCore -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtSql -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I.moc -isystem /usr/include/postgresql -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o .obj/qsql_psql.o qsql_psql.cpp
qsql_psql.cpp: In constructor ‘QPSQLDriverPrivate::QPSQLDriverPrivate()’:
qsql_psql.cpp:152:68: error: no matching function for call to ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriver::DbmsType)’
  152 |     QPSQLDriverPrivate() : QSqlDriverPrivate(QSqlDriver::PostgreSQL) 
      |                                                                    ^
In file included from qsql_psql.cpp:55:
/usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:66:5: note: candidate: ‘QSqlDriverPrivate::QSqlDriverPrivate()’
   66 |     QSqlDriverPrivate()
      |     ^~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:66:5: note:   candidate expects 0 arguments, 1 provided
/usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:61:7: note: candidate: ‘QSqlDriverPrivate::QSqlDriverPrivate(const QSqlDriverPrivate&)’
   61 | class QSqlDriverPrivate : public QObjectPrivate
      |       ^~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:61:7: note:   no known conversion for argument 1 from ‘QSqlDriver::DbmsType’ to ‘const QSqlDriverPrivate&’
/usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:61:7: note: candidate: ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriverPrivate&&)’
/usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:61:7: note:   no known conversion for argument 1 from ‘QSqlDriver::DbmsType’ to ‘QSqlDriverPrivate&&’
make[1]: *** [Makefile:384: .obj/qsql_psql.o] Error 1
make[1]: выход из каталога «/home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql»
make: *** [Makefile:45: sub-psql] Error 2
What's happening? I just need to work with SQL, but that's all. If we open the sqldrivers.pro project using QtCreator, and try to compile, we get 3 errors:

/home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp:147: error: no matching function for call to ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriver::DbmsType)’
/home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp:147:73: error: no matching function for call to ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriver::DbmsType)’
  147 |     inline QSQLiteDriverPrivate() : QSqlDriverPrivate(QSqlDriver::SQLite) 
      |                                                                         ^
/home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql/qsql_psql.cpp:152: error: no matching function for call to ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriver::DbmsType)’
/home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql/qsql_psql.cpp:152:68: error: no matching function for call to ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriver::DbmsType)’
  152 |     QPSQLDriverPrivate() : QSqlDriverPrivate(QSqlDriver::PostgreSQL) 
      |                                                                    ^
:-1: Error: [Makefile:845: .obj/qsql_sqlite.o] Error 1

如何获取插件? 我正在使用communiti QtCreator、PostgreSQL 13.1、Ubuntu 20.04。

如果我输入命令“sudo apt install postgresql-client-13” 然后终端写道“已经安装了最新版本的 postgresql-client-13 软件包 (13.1-1.pgdg20.04 + 1)。 postgresql-client-13 被标记为手动安装。”

“export QT_DEBUG_PLUGINS = 1”之后的输出是巨大的,甚至比程序本身的代码还要大。 在这里,您建议在那里寻找什么?

我失去了希望,我还能做什么?

“export QT_DEBUG_PLUGINS = 1”后的日志https://cloud.mail.ru/public/3tnm/Zn2pjp1qr

我在 'home/myname/Qt' 文件夹中安装了 Qt 但正如我现在看到的日志,有一个独立的文件夹 /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/ 我没有创建它。 现在我在 '~/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers' 文件夹中运行 make 并得到了新的错误:

anton@home:~/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers$ make sub-psql
cd psql/ && ( test -e Makefile || /usr/lib/qt5/bin/qmake -o Makefile /home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql/psql.pro PSQL_INCDIR=/usr/include/pgsql ) && make -f Makefile
make[1]: вход в каталог «/home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql»
g++ -c -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -O2 -std=c++1z -fvisibility=hidden -fvisibility-inlines-hidden -fno-exceptions -Wall -W -Wvla -Wdate-time -Wshift-overflow=2 -Wduplicated-cond -Wno-stringop-overflow -Wno-deprecated-copy -Wno-redundant-move -Wno-format-overflow -Wno-init-list-lifetime -D_REENTRANT -fPIC -DQT_NO_JAVA_STYLE_ITERATORS -DQT_DEPRECATED_WARNINGS -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_EXCEPTIONS -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_NO_DEBUG -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -I. -isystem /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8 -isystem /usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore/5.12.8 -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore/5.12.8/QtCore -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtSql -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I.moc -isystem /usr/include/postgresql -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o .obj/qsql_psql.o qsql_psql.cpp
qsql_psql.cpp: In constructor ‘QPSQLDriverPrivate::QPSQLDriverPrivate()’:
qsql_psql.cpp:152:68: error: no matching function for call to ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriver::DbmsType)’
  152 |     QPSQLDriverPrivate() : QSqlDriverPrivate(QSqlDriver::PostgreSQL) 
      |                                                                    ^
In file included from qsql_psql.cpp:55:
/usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:66:5: note: candidate: ‘QSqlDriverPrivate::QSqlDriverPrivate()’
   66 |     QSqlDriverPrivate()
      |     ^~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:66:5: note:   candidate expects 0 arguments, 1 provided
/usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:61:7: note: candidate: ‘QSqlDriverPrivate::QSqlDriverPrivate(const QSqlDriverPrivate&)’
   61 | class QSqlDriverPrivate : public QObjectPrivate
      |       ^~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:61:7: note:   no known conversion for argument 1 from ‘QSqlDriver::DbmsType’ to ‘const QSqlDriverPrivate&’
/usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:61:7: note: candidate: ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriverPrivate&&)’
/usr/include/x86_64-linux-gnu/qt5/QtSql/5.12.8/QtSql/private/qsqldriver_p.h:61:7: note:   no known conversion for argument 1 from ‘QSqlDriver::DbmsType’ to ‘QSqlDriverPrivate&&’
make[1]: *** [Makefile:384: .obj/qsql_psql.o] Ошибка 1
make[1]: выход из каталога «/home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql»
make: *** [Makefile:45: sub-psql] Ошибка 2

另一个有趣的点,如果你在 QTCreator 中打开 SQLPlagin 项目,你可以看到有错误的源 /home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/sqldrivers.pro 有 3 个错误

/home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql/qsql_psql.cpp:152: error: no matching constructor for initialization of 'QSqlDriverPrivate' 

:-1: error: [Makefile:845: .obj/qsql_sqlite.o] Error 1

/home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql/qsql_psql.cpp:152: error: no matching function for call to ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriver::DbmsType)’
/home/anton/Qt/5.15.2/Src/qtbase/src/plugins/sqldrivers/psql/qsql_psql.cpp:152:68: error: no matching function for call to ‘QSqlDriverPrivate::QSqlDriverPrivate(QSqlDriver::DbmsType)’
  152 |     QPSQLDriverPrivate() : QSqlDriverPrivate(QSqlDriver::PostgreSQL) 

【问题讨论】:

您使用什么版本的 Qt 以及您是如何安装它的?我指出它是因为在您的帖子的一部分中,您似乎使用了 Qt 5.15.2 的源代码,但根据您使用的日志,您使用 Qt 5.12.8 进行编译 我使用在线安装程序安装了它,我昨天重新安装了它 - 这意味着最新版本(现在我认为是 6),但我安装了所有组件。我认为这会有所帮助。 如果您使用不同的版本,那么您在帖子中提供的版本必须与该信息匹配,但显然不匹配。请确保您使用的是哪个版本,并使用新日志更新您的帖子信息。不要只是假设您使用的是 Qt6,而是要确保您是。 qmake -v QMake version 3.1 Using Qt version 5.12.8 in /usr/lib/x86_64-linux-gnu great ((但是我在在线安装程序中插入了所有标记,应该都有版本。或者我不了解 Qt。 那是你用apt-get安装的操作系统仓库的Qt但是你指出你使用在线安装程序安装Qt,我看到你的cmets矛盾,请澄清一下跨度> 【参考方案1】:

如果你想在 Ubuntu 中使用 PostgreSQL 插件,只需安装客户端,Qt 提供插件即可:

sudo apt-get install libpq-dev

另一方面,如果你想编译插件(这通常是不必要的),那么你必须遵循以下步骤:

sudo apt-get install libpq-dev
git clone -b 5.15.2 https://code.qt.io/qt/qtbase.git
cd qtbase/src/plugins/sqldrivers
~/Qt/5.15.2/gcc_64/bin/qmake -- PSQL_INCDIR=/usr/include/pgsql
make sub-psql
make install

【讨论】:

成功了,编译通过了。仍然需要了解生成的插件在哪里以及如何将其添加到 Qt。 @Anton1978 在运行make install 命令时已添加到Qt 奇怪,仍然 - QSqlQuery::exec: 数据库未打开 QSqlError("", "未加载驱动程序", "未加载驱动程序") ("QSQLITE", "QODBC", "QODBC3", "QPSQL", "QPSQL7") ,我怀疑我的操作系统有问题 @Anton1978 您确定您使用的是托管在~/Qt/5.15.2 中的Qt 吗?我认为您正在使用系统 Qt (Qt 5.12.8) 进行编译,如果是这样,则必须使用命令 sudo apt-get install '^libqt5sql5-*' 安装系统插件 我认为是的,在 Qt Creator 中选择了桌面 Qt_5_15_2_GCC_64bit 调试器

以上是关于如何在ubuntu上去更新postgresql的主要内容,如果未能解决你的问题,请参考以下文章

Ubuntu 19.04初体验

ubuntu系统 迅雷安装上去后启动不了

如何在ubuntu上更新numpy

如何更新/替换ubuntu16.04内核

kali linux(ubuntu) |windows物理机和linux虚拟机共享文件

双系统安装,机器上已经安装了centos,怎么可以将ubuntu也装上去