postgresql

c++ convert postgres timestamp without time zone to time_t

拥有回忆 提交于 2020-12-11 02:52:29
问题 I'm connecting from c++ to postgreSQL using libpq library. I request and obtain the date (timestamp without time zone) from postgreSQL, but the result has an offset that I don't know how to fix. Postgres table: id date integer timestamp without time zone 29996 2014-02-28 23:59:00 result in C++ code: id: 29996, Date: Sat Mar 01 10:59:00 2014 You can see that the date has the offset. Below is the code that I'm using. Any help will be greatly appreciated PGconn *m_connection; PGresult *res;

pgAdmin的Desktop Mode设置允许远程访问

女生的网名这么多〃 提交于 2020-12-10 11:29:26
有时候因为一些安全设置或权限问题,不允许用户直接访问PostgreSQL数据库,但是Support系统的用户必须要访问数据库. 那怎么办呢? 在一台可以访问PostgreSQL的服务器上安装pgAdmin,然后让用户使用浏览器远程访问pgAdmin,访问PostgreSQL数据库, 那么pgAdmin如何设置允许远程访问呢?其实pgAdmin有Desktop Mode和Server Mode两种模式,对于Server Mode的话,这个根本不是问题。 下面介绍Desktop Mode的pgAdmin如何允许远程访问,这个是在对pgAdmin这个工具不熟悉的情况下的一个尝试。很多时候,我们都像一个蹒跚学步的小孩一样,需要时间和尝试才会熟练的掌握一款工具!过程中总有磕磕碰碰。 下面测试环境为Windows Server 2019 Datacenter版本,在pgAdmin的安装目录,例如,C:\Program Files\pgAdmin 4\v4\web目录下(这里是默认安装,根据实际情况找到安装目录)config.py文件, 找到DEFAULT_SERVER参数,将其值修改为'0.0.0.0'后 # This option allows the user to host the application on a LAN # Default hosting is on

理解postgreSQL中的prepared transactions和处理孤儿(orphans)事务

橙三吉。 提交于 2020-12-10 10:00:00
Prepared transactions是PostgreSQL的一个关键特性。理解该特性提供的功能和处理任何潜在的陷阱对于系统的维护是很关键的。所以,我们来深入研究一下具体什么是prepared transactions。 关于事务 在数据库系统中,事务是一种处理通常包含多个语句的块中的全部或零个语句的方法。在提交整个块之前,该块中语句的结果对其他事务不可见。 如果事务失败或回滚,则对数据库完全没有影响。 事务依附于会话。但是,当要执行与会话独立的事务时(也有其他好处)。这就是“prepared transactions”的来源。 prepared transactions prepared transaction是独立于会话、抗崩溃、状态维护的事务。事务的状态存储在磁盘上,这使得数据库服务器即使在从崩溃中重新启动后也可以恢复事务。在对prepared transaction执行回滚或提交操作之前,将一直维护该事务。 PostgreSQL文档声明,在一个已存在的事务块中,可以使用prepare transaction ’transaction_id‘命令创建一个prepared transaction。它进一步声明该过程为两阶段提交准备了一个事务。 此外,建议应用程序或交互式会话不要使用prepared transaction。理想情况下

NGINX TLS termination for PostgreSQL

喜夏-厌秋 提交于 2020-12-09 09:55:20
问题 I’ve been trying to use NGINX as a TLS terminator for my PostgreSQL database but without success. When I try to connect to the database I get the following error: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. When I remove the ssl option in listen I can connect without any errors. I’ve tried running another service(Eclipse Mosquitto) with the same NGINX settings, TLS enabled, and it works fine. I’m using

NGINX TLS termination for PostgreSQL

你。 提交于 2020-12-09 09:54:40
问题 I’ve been trying to use NGINX as a TLS terminator for my PostgreSQL database but without success. When I try to connect to the database I get the following error: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. When I remove the ssl option in listen I can connect without any errors. I’ve tried running another service(Eclipse Mosquitto) with the same NGINX settings, TLS enabled, and it works fine. I’m using

PostgreSQL select max with group by and additional value [duplicate]

我只是一个虾纸丫 提交于 2020-12-09 06:53:33
问题 This question already has answers here : Select first row in each GROUP BY group? (17 answers) Closed 5 years ago . With the following data from a SELECT * FROM (SELECT...) AS foo : ID Country Area 1 US 100 1 UK 200 2 AU 150 2 NZ 250 how can you select the top area and country by ID ? So GROUP BY ID and MAX(DESC) but also include the County . The the result of the query would be: 1 UK 200 2 NZ 250 回答1: SELECT DISTINCT ON (ID) ID, Country, Area FROM foo ORDER BY ID, Area DESC NULLS LAST;

PostgreSQL select max with group by and additional value [duplicate]

萝らか妹 提交于 2020-12-09 06:52:27
问题 This question already has answers here : Select first row in each GROUP BY group? (17 answers) Closed 5 years ago . With the following data from a SELECT * FROM (SELECT...) AS foo : ID Country Area 1 US 100 1 UK 200 2 AU 150 2 NZ 250 how can you select the top area and country by ID ? So GROUP BY ID and MAX(DESC) but also include the County . The the result of the query would be: 1 UK 200 2 NZ 250 回答1: SELECT DISTINCT ON (ID) ID, Country, Area FROM foo ORDER BY ID, Area DESC NULLS LAST;

Knex silently converts Postgres timestamps with timezone and returns incorrect time

纵然是瞬间 提交于 2020-12-08 06:58:09
问题 I have a table in my psql database with a "trigger_time" column of type "TIMESTAMP WITH TIME ZONE DEFAULT now()" I data in the row is this 2018-06-27 15:45:00-03 . When running from psql console SELECT trigger_time AT TIME ZONE 'UTC' FROM tasks WHERE task_id = 1; this query returns "2018-06-27 18:45:00". Similarly when I run SELECT trigger_time AT TIME ZONE 'America/Glace_Bay' FROM tasks WHERE task_id = 1; I get 2018-06-27 15:45:00 Using knex.raw("SELECT trigger_time AT TIME ZONE 'America

AWS RDS public access

你说的曾经没有我的故事 提交于 2020-12-08 05:47:04
问题 I am stumped with AWS configuration. My goal is to create a database that's accessible from inside and outside the network. Here is what I have. RDS instance runs postgresql. Connections from inside the VPC work correctly. The endpoint is set up to be publicly accessible - and when accessed from the outside, does in fact resolve. However, the connection hangs, indicating the traffic is blocked by somebody. Security group is good: Inbound: Port 5432 from 0.0.0.0/0 Outbound: all from 0.0.0.0/0

Postgres return a default value when a column doesn't exist

浪子不回头ぞ 提交于 2020-12-08 05:37:54
问题 I have a query where I essentially want a fallback value if a certain column is missing. I was wondering if I can handle this purely in my query (rather than probing first and sending a seperate query. In essence i'm looking for an equivalent to COALESCE that handles the case of a missing column. Imagine the following 2 tables. T1 id | title | extra 1 A | value - and - T2 id | title 1 A I'd like to be able to SELECT from either of these tables WITH THE SAME QUERY. eg, if t2 actually had an