Questions tagged [postgresql]

All versions of PostgreSQL. Add an additional version-specific tag like postgresql-11 if that context is important.

Filter by
Sorted by
Tagged with
0
votes
2answers
37 views

How to count decimals without zeros

How can I count all decimal place up to the first zero For example I have a column named x with an entry of numeric datatype value 1.955000000 I want to count the decimal places without the zeros. ...
0
votes
1answer
18 views

Postresql dynamic index creation for many tables

How can I create an index in Postgres dynamically over many tables but always with different names. Lets assume table x has a column y with all table names of hundreds tables which need to get an ...
0
votes
1answer
42 views

How to deal with different badges in Postgres Explain Visualizer?

I've been working with several DBMS during my career, but always Oracle/Sql Server/MySql. Now I have to deal with PostgreSQL and my first task is to tune several queries to speed them, as our DB is ...
0
votes
1answer
23 views

Error: pq: 1 columns must reference exactly 1 columns in referenced table (found 2) [closed]

I have a few tables and I am facing this issue most likely with the table "item". When I remove restaurant_id and category_id, it works fine. CREATE TABLE IF NOT EXISTS restaurant ( id ...
1
vote
2answers
32 views

copy entire PostgreSQL cluster to another (identical) server

I'm looking to clone a PostgreSQL 10 cluster from server1 to server2, which is running the same Postgres version on identical hardware. The purpose is load-balancing and HA. Things to keep in mind: ...
3
votes
2answers
4k views

starting pgbouncer on startup

I installed pgbouncer and configured it and it starts only via using this command pgbouncer /etc/pgbouncer/pgbouncer.ini however using service pgbouncer start it dose not start. I then set up ...
2
votes
1answer
152 views

Inefficient execution plan selected by postgresql

I have the following SQL query explain analyze select CERTIFICATE_ID, SERIAL_NUMBER, SUBJECT_DISTINGUISHED_NAME, NOT_BEFORE, NOT_AFTER, FIRST_SEEN, REVOKED, LINT_ERRORS from (...
1
vote
1answer
22 views

sequence keys for static data

In my data model I have some static data that is added to over time as the system changes. For instance: create table region (id SERIAL,crname TEXT); customer has a link to the region, my system ...
0
votes
1answer
32 views

Schema and Query design for table with multiple languages [closed]

I've been researching on how to create a schema for a database that contains multiple languages. So I decided to separate the translations on a different table with a column as the language and ...
6
votes
1answer
4k views

Update by iterating table in batches faster than whole table in PostgreSQL

I have a table with approximately one million rows. It is being used in production and I ran an UPDATE which covers ~95% of those rows. After five hours I cancelled the request because it was taking ...
0
votes
1answer
262 views

SQL query to get the leaf record in a parent-child relationship

I use PostgreSQL. I have 2 tables, products and product_renewals. Products +----+--------+ | id | name | +----+--------+ | 1 | Foo | | 2 | Bar | | 3 | Foo | | 4 | Foo | +----+------...
1
vote
1answer
109 views

Postgres Column Level Security

I have a schema snow within a database testdb. I'm trying to achieve column level security for my users. My users are boss, manager and intern. I set all of this table up as the superuser me. They are ...
0
votes
1answer
24 views

How to insert values to one table from the table stored in another database in postgresql?

Here is the structure of table: `* Table 1 of database A contains mobile number and userId and both field cannot be blank I want to fetch data from table 1 of database A and insert that with some ...
0
votes
1answer
98 views

Pass 'interval' value to date_trunc function in PostgreSQL procedure

I am fetching the "age" of two timestamp columns (End and Start) and further choosing it as to_char 'MM' format. So I have the difference of the months from two timestamp columns. The syntax in the ...
1
vote
1answer
157 views

Full text search on larger text rows

I am wondering what is the best practice to use the right query in my case. The problem is I tried the LIKE and ILIKE and it was faster then pg_trgm and the postgres full text search, because they ...
2
votes
1answer
105 views

Accessing a row directly at a table in PostgreSQL by using the PostgreSQL's internal library

I am writing a PostgreSQL extension using the C language. I would like to do the following tasks: Store a set of rowids (or other row identifier, like ctid). Each rowid uniquely represents a row in ...
4
votes
2answers
787 views

Which index type is best suited for exact-match against a list of values?

I have this table: CREATE TABLE public.foos ( id integer NOT NULL, bar_string character varying ); I want to do this query: SELECT id from foos where bar_string in ('one', 'two', 'three') ...
0
votes
1answer
170 views

How to use windowing functions to find gaps in sequences grouped by a column, in PostgreSQL

I have a table structure which has 2 columns: client_id, order_no, and both are integers. I'd like to find gaps in order_no in the data so that, for example, for a table containing these rows: 42, 1 ...
0
votes
0answers
62 views

Postgres TX Wraparound - confused

i am running postgres on aws and trying to get my head around the "tx wraparound topic". i executed the following steps to "play" around take snaptshot of production database (here "our_main_db") ...
2
votes
1answer
31 views

Why does DELETE not work after an UPDATE in a CTE?

CREATE table test ( id integer, x integer ); INSERT INTO test VALUES (1, 1); SELECT works: WITH res AS ( UPDATE test SET x = 10 WHERE id = 1 RETURNING id ) SELECT id FROM test WHERE ...
1
vote
1answer
9 views

Postgresql replication slot used by barman has a long replay_lag

I set up barman using wal streaming, I just notice I have a hug replay_lag. I'd like to keep it down to 0 but have no idea about how to do this. I also have a database replica and it is working fine. ...
24
votes
4answers
38k views

Very slow DELETE in PostgreSQL, workaround?

I have a database on PostgreSQL 9.2 that has a main schema with around 70 tables and a variable number of identically structured per-client schemas of 30 tables each. The client schemas have foreign ...
0
votes
2answers
34 views

Does enabling pg_stat_statements reduce disk space?

Recently I was informed that since enabling pg_stat_statements, the available disk space is dropping fast. I don't think it's caused by that, but I wonder: Does enabling pg_stat_statements reduce disk ...
4
votes
1answer
136 views

Calculating balance sheet with a single query

I have this schema for double entry bookkeeping system: CREATE TABLE account ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, parent_id INTEGER REFERENCES account(id), UNIQUE (name, ...
-1
votes
1answer
14 views

DBD::Pg::st execute failed: ERROR: canceling statement due to user request

I am using postgresql with pgadmin, I am getting following error DBD::Pg::st execute failed: ERROR: canceling statement due to user request CONTEXT: SQL statement "TRUNCATE mystats_na_apple....
5
votes
1answer
176 views

Will autovacuum block DROP or TRUNCATE?

When the autovacuum process is vacuuming a large table, will queries like DROP and TRUNCATE be blocked until vacuuming completed? In the documentation,it says Also, the standard form of VACUUM can ...
1
vote
1answer
454 views

Window aggregate resulting in slow query on postgres 9.6

I'm using Postgresql 9.6 and I'm running into a performance issue. I have a relatively simple query: explain analyze SELECT * FROM ( SELECT A.person_id, O.session_id, timestamp_ AS ...
0
votes
1answer
14 views

pg_restore fails with drop default on identity column

Trying to restore a Postgres 10.6 database via pg_restore, and it seems to want to do a DROP DEFAULT when it should be doing a DROP IDENTITY during the clean phase. See below: pg_restore --verbose -...
0
votes
1answer
146 views

How to mount a pg_basebackup on a stand alone server to retrieve accidently deleted data

Had a bit of a brain fade the other day and deleted all the rows in one of the tables in our database and didn't realise until a couple of hours later. I have a pg_basebackup file system copy created ...
0
votes
1answer
106 views

Large bulk insert performance difference PostgreSQL vs MariaDB (InnoDB)

I've got the very same single-table definition in both PostgreSQL 11.4 and MariaDB 10.4.6 (InnoDB) and I'm seeing a significant difference in INSERT performance I cannot explain for PostgreSQL. My ...
1
vote
1answer
27 views

Why disable Postgres Autovacuum?

I've got a task to work with a 9.6 Postgres DB, and for some reason Autovacuum is disabled. The database was extremely slow, and after a manual VACUUM it could breathe again. The point is, why ...
1
vote
1answer
16 views

How I can find out the foreign wrapper that a foreign table belongs to?

I have found that the following query lists all my foreign tables in my PostgreSQL database: select * from information_schema."tables" where table_type='FOREIGN TABLE'; Now I want to find out the ...
0
votes
1answer
24 views

How to Bulk Insert sqlalchemy subclasses

I am trying to bulk insert SQL-Alchemy Subclasses into the parent table and their respective tables ie fruits tables -> Apple Table and so I insert a table of APPLE and it will insert both the row ...
1
vote
0answers
15 views

How to get db “state version seq” in postgres?

I need to run a script on every database change. The script works on diffs, so I need to know if I handled the previous state (the handler script could be down for some time for example). One way I ...
1
vote
2answers
442 views

PostgreSQL truncating values of real numeric type

Using PostgreSQL 9.2 on Windows Server 2007, I have the following table: CREATE TABLE aaa_dens (read_no INT, position REAL PRIMARY KEY); Some values in position have 4 or more digits after the ...
0
votes
1answer
27 views

How to Calculate Month over Month User Retention based on already active users (not based on user signup date)?

I have a Table which tracks User activity (i-e user started a session at what time ?). This table contains the data from Dec 2018 Till now. I need to calculate monthly retention (not based on signup ...
1
vote
1answer
121 views

Started using UUID's as primary key, would like to execute union of entities with BigSerial Primary Key

Some of my newer tables are now using UUID type fields as PKey and older tables are still using bigserial. I have several tables (let's call them entities) I would like to query returning the primary ...
3
votes
1answer
91 views

Finding optimal indices, different query competing indices

My schema: create TABLE "logs" ( "id" serial not null default nextval('logs_id_seq'::regclass), "request" varchar(1024), "token" varchar(512) default NULL, "was_batch_request" bool ...
0
votes
1answer
67 views

Postgresql function equivalent to Excel's NORMSINV function?

I need Excel's NORMSINV equivalent function for PostgreSQL, preferably plpgsql function. Can somebody help? For reference, here is Excel's normsinv function explained: https://support.microsoft.com/en-...
0
votes
0answers
22 views

Single metadata base table in Postgres

I am a fan of adding timestamps to tables in the form of created_at, updated_at and deleted_at. But it can be tedious to add these fields to every table. I was wondering, is it a bad design decision ...
1
vote
1answer
736 views

Troubleshooting PgPool Query Lags

I have been using PGpool-II for quite a while but just noticed an intermittent lag (slow request taking about 20s to execute) which I am able to replicate consistently. Before I explain here is a ...
0
votes
1answer
43 views

Postgresql, escape character in string_agg function

Question, can I add escape character \ just for fields param_name and value for this? string_agg(distinct '{name:"' || param_name || '",value:"' || value || '"}',',') as "params", Result is. {name:"...
0
votes
1answer
20 views

postgres function definition not saving top whitespace

For reference I am running postgres 9.6 . I'd like to write functions inside of postgres where the top of the function saves. create or replace function apqp.apqp_list_gentex_tool_report_getlist(...
6
votes
1answer
2k views

Multiple on conflict targets

I have two unique indexes on columns a and b. I need something like this: insert into my_table (a, b) values (1, 2), (1, 2) on conflict (a) do update set c = 'a_violation' on conflict (b) do update ...
2
votes
1answer
103 views

SELECT operation with four joins results in bad performance

I'm having problems with a slow query. The query purpose is to get doers ids for X job who didn't exceed specified limits on realizations and also are in range of possible job places. Resources ...
0
votes
1answer
19 views

How can I see what query is emitted by the query parser?

Consider this snippet: create table tbl_1(name text); create table tbl_2(name text); create function my_insert(_name text) returns text language sql as $$ insert into tbl_2(name) values (...
0
votes
0answers
16 views

How to achieve this Nested Complex postgresql schema CRUD?

I'm trying to achieve this complex schema. { relation1_id : Number, ... ... item_caption: [ { caption: '', subcaption: '', products: [ { ...
0
votes
1answer
20 views

pgadmin: can't insert jsonb[] values with strings

I have jsonb[] column and it allows me to insert some nested arrays, but only with number values like {{1,2,3}, {4,5,6}, {7,8,9}}. I'm not talking about inserting some nested objects like {{"one": "...
3
votes
1answer
1k views

OCIEnvCreate failed to create environment handle after installing oracle_fdw

I'm want use Postgresql 9.3 in CentOS 7 and add extention oracle_fdw. but when use this extenstion i get error OCIEnvCreate failed to create environment handle after installing oracle_fdw. my ...
0
votes
1answer
14 views

How to reset object permissions to default?

I've just been added to a project using Postgresql 11.4 where database security has been an afterthought. As part of tightening things up, I've used ALTER DEFAULT PERMISSIONS to set sane ACLs on any ...