Prometheus postgres exporter not showing metric with interval time with single quotes - postgresql

I inserted the following postgres query in the queries.yaml file with Labels and metric.
pg_long_running_query_details:
query: "SELECT distinct a.datname as database , a.usename as user , round(extract(epoch from statement_timestamp()) - extract(epoch from a.query_start)) as age FROM pg_stat_activity a JOIN pg_locks l ON l.pid = a.pid WHERE age(statement_timestamp(), query_start) > interval U&'10 minutes' limit 5"
metrics:
- database:
usage: "LABEL"
description: "Name of the database"
- user:
usage: "LABEL"
description: "Name of the user"
- age:
usage: "GAUGE"
description: "The age in seconds"
I would expect pg_long_running_query_details_age metric flowing through prometheus. Not only there is no metric but no errors in the exporter too. The query works perfectly fine in psql cli.
When I remove the interval time, i can see the metric. So i'm guessing, its something to do with the single quotes.
What did you see instead? Under which circumstances?
No metric in the name 'pg_long.*'
Environment
Ubuntu
System information:
Linux 4.15.0-135-generic x86_64
postgres_exporter version:
Postgres Exporter - Wrouesnel v0.5.1.
postgres_exporter flags:
insert list of flags used here
PostgresSQL version:
PostgreSQL 11.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36), 64-bit
Logs:
No error logs in the exporter.

Related

Postgis st_transform error: SQL Error [XX000]: ERROR: could not form projection (LWPROJ) from 'srid=7801' to 'srid=4326'

I have 4 servers with the same versions of OS (Ubuntu 20.04), Postgis and Postgre:
POSTGIS="3.2.1 5fae8e5" [EXTENSION] PGSQL="130" GEOS="3.10.1-CAPI-1.16.0" PROJ="6.3.1" LIBXML="2.9.10" LIBJSON="0.13.1" LIBPROTOBUF="1.3.3" WAGYU="0.5.0 (Internal)"
PostgreSQL 13.6 (Ubuntu 13.6-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bit
The query below works on any server except one:
`
SELECT
st_asgeojson(st_transform("table-name".geom, 4326)) AS way
FROM "table-name"
`
The server with the issue responds this error:
SQL Error [XX000]: ERROR: could not form projection (LWPROJ) from 'srid=7801' to 'srid=4326'
I upgraded the postgis server to 3.3.2 but the result is the same.
Can you help me?

Postgres set work_mem is not reflecting in session

My Postgres version is 9.6 ("PostgreSQL 9.6.16 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23), 64-bit"). I am trying to set the work_mem value for a session but it is not reflecting value. In a query window, I am doing following
show work_mem --displays "2MB"
SET work_mem = '256MB'; --displays "Query returned successfully with no result in 32 msec." in output pane
show work_mem --displays "2MB" again
The set command is successfully executed but value is not changed. please suggest something.

Syntax error at or near "INTERVAL" while creating PARTITIONed table in PG

I am trying to create a partitioned table in edb 9.6.10 . I am getting the following error when I am trying to do so
edb=# create table employee (id int, join_date timestamp(6)) PARTITION BY RANGE (join_date) INTERVAL ('1 day'::interval);
ERROR: syntax error at or near "INTERVAL"
LINE 1: ...date timestamp(6)) PARTITION BY RANGE (join_date) INTERVAL (...
^
Please let me know what I am doing wrong here.
As far as I can tell, the feature you are trying to use only exists in EDB's paid product, and even there it only became available in v12.
This PARTITION BY RANGE INTERVAL is only supported from version 12 and onward.
See the difference of behaviour for the same query in version11 and version12.
edb=# select version;
PostgreSQL 11.11 (EnterpriseDB Advanced Server 11.11.20) on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36), 64-bit
(1 row)
edb=# create table employee (id int, join_date timestamp(6)) PARTITION BY RANGE (join_date) INTERVAL ('1 day'::interval);
ERROR: syntax error at or near "INTERVAL"
LINE 1: ...date timestamp(6)) PARTITION BY RANGE (join_date) INTERVAL (...
and in Version12 we get
edb=# select version();
PostgreSQL 12.4 (EnterpriseDB Advanced Server 12.4.5) on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36), 64-bit
(1 row)
edb=# create table employee (id int, join_date timestamp(6)) PARTITION BY RANGE (join_date) INTERVAL ('1 day'::interval);
CREATE TABLE
Moreover, this 'INTERVAL' syntax is only available in EnterpriseDB paid product. In the case of community Postgres e.g V13 you will still get the same error.
[root#localhost bin]# ./psql -U postgres -d postgres -p 5432
psql (13.2)
Type "help" for help.
postgres=# create table employee (id int, join_date timestamp(6)) PARTITION BY RANGE (join_date) INTERVAL ('1 day'::interval);
ERROR: syntax error at or near "INTERVAL"
LINE 1: ...date timestamp(6)) PARTITION BY RANGE (join_date) INTERVAL (...

Why is my Hive QL Query that I run in SSMS via Openquery through the Hortonworks ODBC Driver producing an error?

I set up a connection to a Hive server using the Hortonworks ODBC Driver for Apache Hive. Version info is below:
OS: Windows Server 2012 R2 Standard
Hive: 1.2.1000.2.6.5.4-1
Hadoop: 2.7.3.2.6.5.4-1
Hortonworks ODBC Driver for Apache Hive
ODBC Version: 03.80
Driver Version: 2.1.12.1017
Bitness: 64-bit
Locale: en_US
I can run the queries below using the connector that I configured in Teradata SQL Assistant with no issues. I set up my DSN as a linked server in SSMS. However, when I attempt to run the queries in SSMS using openquery, I have some issues. Info on my SQL Server is below:
Microsoft SQL Server 2016 (SP2-CU3) (KB4458871) - 13.0.5216.0 (X64) Sep 13 2018 22:16:01 Copyright (c) Microsoft Corporation Enterprise Edition (64-bit) on Windows Server 2012 R2 Standard 6.3 <X64> (Build 9600: ) (Hypervisor)
Here is some info on the table that I am querying:
Table Name: instrumentapps_event
Using OPENQUERY, I am capable of querying the Hive DB through SSMS with the following query:
SELECT * FROM OPENQUERY(KMhivehttp, 'select * from dmfwk_gold.instrumentapps_event')
The above query returns the contents of the desired table. However, the query below produces an error:
SELECT * FROM OPENQUERY(KMhivehttp, 'select * from dmfwk_gold.instrumentapps_event WHERE to_date(from_unixtime(UNIX_TIMESTAMP(load_ts,''yyyy/MM/dd''))) >= to_date(''2019-03-01'')')
The error is as follows:
Msg 7355, Level 16, State 1, Line 1
The OLE DB provider "MSDASQL" for linked server "KMhivehttp" supplied inconsistent metadata for a column. The name was changed at execution time.
How can I fix this?
While I'm unsure how to fix the problem that I previously faced (I suspect it to be a bug with the Hortonworks ODBC driver), I did discover a workaround.
Instead of running:
SELECT * FROM OPENQUERY(KMhivehttp,
'SELECT *
FROM dmfwk_gold.instrumentapps_event
WHERE to_date(from_unixtime(UNIX_TIMESTAMP(load_ts,''yyyy/MM/dd''))) >=
to_date(''2019-03-01'')
')
I now use:
SELECT * FROM OPENQUERY(KMhivehttp, 'select * from dmfwk_gold.instrumentapps_event')
WHERE load_ts >= CAST('2019-03-01' AS DATE);
This allows me to avoid any metadata errors.

How do I use ROW_NUMBER in DB2 10 on z/OS?

I am running a SQL query and trying to break the results down into chunks.
select task_id, owner_cnum
from (select row_number() over(order by owner_cnum, task_id)
as this_row, wdpt.vtasks.*
from wdpt.vtasks)
where this_row between 1 and 5;
That SQL works with DB2 10.5 on Windows and Linux, but fails on DB2 10.1 on z/OS with the following error messages:
When I run the SQL from IBM DataStudio 4.1.1 running on my Windows machine connected to the database, I am getting:
ILLEGAL SYMBOL "<EMPTY>". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: CORRELATION NAME. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.18.60
When I run my Java program on a zLinux system connecting to the database, I get the following error:
DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=<EMPTY>;CORRELATION NAME, DRIVER=3.65.97
Any ideas what I'm doing wrong?
In some DB2 versions you must use a correlation name for a subselect, as suggested by the error message:
select FOO from (
select FOO from BAR
) as T
Here "T" is the correlation name.