Questions tagged [postgresql-9.4]

PostgreSQL version 9.4

Filter by
Sorted by
Tagged with
37
votes
2answers
24k views

Refresh materalized view incrementally in PostgreSQL

Is it possible to refresh a materialized view incrementally in PostgreSQL i.e. only for the data that is new or has changed? Consider this table & materialized view: CREATE TABLE graph ( ...
26
votes
2answers
11k views

“Recheck Cond:” line in query plans with a bitmap index scan

This is a spin-off from comments to the previous question: Postgres 9.4.4 query takes forever Using PostgreSQL 9.4, there always seems to be a Recheck Cond: line after bitmap index scans in query ...
24
votes
3answers
26k views

Query the definition of a materialized view in Postgres

I'm wondering how to query the definition of a materialized view in Postgres. For reference, what I hoped to do is very similar to what you can do for a regular view: SELECT * FROM information_schema....
23
votes
5answers
83k views

SELECT DISTINCT on multiple columns

Supposing we have a table with four columns (a,b,c,d) of the same data type. Is it possible to select all distinct values within the data in the columns and return them as a single column or do I ...
23
votes
2answers
15k views

Does Postgres preserve insertion order of records?

For example when I'm using query which returns record ids INSERT INTO projects(name) VALUES (name1), (name2), (name3) returning id; Which produce output: 1 2 3 Will this ids point to corresponding ...
23
votes
1answer
38k views

PostgreSQL JSON query array against multiple values

I want to write a query against jsonb type in Postgres that given an array of customers IDs will find corresponding groups. Given this example table: CREATE TABLE grp(d JSONB NOT NULL); INSERT INTO ...
22
votes
2answers
40k views

PostgreSQL joining using JSONB

I have this SQL: CREATE TABLE test(id SERIAL PRIMARY KEY, data JSONB); INSERT INTO test(data) VALUES ('{"parent":null,"children":[2,3]}'), ('{"parent":1, "children":[4,5]}'), ('{"parent":...
21
votes
2answers
23k views

Convert right side of join of many to many into array

When using join on many to many relationship the result is split on multiple rows. What I'd like to do is convert the right side of a join into an array so the result is one row. Example with 3 tables:...
19
votes
2answers
14k views

Database “frozen” on ALTER TABLE

Our production environment just froze* this morning for a while when altering a table, adding a column actually. Offending SQL:ALTER TABLE cliente ADD COLUMN topicos character varying(20)[]; * ...
18
votes
3answers
46k views

How to upgrade PostgreSQL from version 8.4 to 9.4?

I want to upgrade my PostgreSQL from version 8.4 to 9.4. The documentation is not very clear to me. Will I lose my old databases if I do the upgrade? How can I backup my old databases if I am to ...
18
votes
1answer
13k views

How do I decompose ctid into page and row numbers?

Each row in a table has a system column ctid of type tid that represents the physical location of the row: create table t(id serial); insert into t default values; insert into t default values; ...
18
votes
1answer
59k views

How to get particular object from jsonb array in PostgreSQL?

I have a field called 'user' that holds a json array that roughly looks like this: "user": [{ "_id" : "1", "count" : "4" }, { "_id" : "3", "count": "4"}] Now I want a query like: select count from ...
18
votes
1answer
12k views

Index not used with `=any()` but used with `in`

Table t has two indexes: create table t (a int, b int); create type int_pair as (a int, b int); create index t_row_idx on t (((a,b)::int_pair)); create index t_a_b_idx on t (a,b); insert into t (a,b)...
18
votes
2answers
19k views

How to do incremental backup every hour in Postgres?

Trying to do an hourly incremental backup of a single Postgres server (Win7 64). I have the following setup in postgresql.conf: max_wal_senders = 2 wal_level = archive archive_mode = on ...
17
votes
2answers
2k views

Trigram search gets much slower as search string gets longer

In a Postgres 9.1 database, I have a table table1 with ~1.5M rows and a column label (simplified names for the sake of this question). There is a functional trigram-index on lower(unaccent(label)) (...
17
votes
5answers
9k views

How to examine PostgreSQL server's SSL certificate?

Suppose there is a PostgreSQL server running and it has SSL enabled. Using "standard" Linux and PostgreSQL tools, how can I examine its SSL certificate? I'm hoping for output similar to what you ...
17
votes
1answer
11k views

How do I split a long PL/pgSQL line of code over multiple lines?

Is there a way to split a long line of PL/pgSQL code over multiple lines? My context is a trigger function where I log inserts into a table as per: INSERT INTO insert_log (log_time, description) ...
16
votes
1answer
15k views

Is there a way to insert multiple rows into a table with default values for all columns?

I can insert multiple rows into a table with default values for all columns the RBAR way: create table course(course_id serial primary key); do $$ begin for i in 1..100000 loop insert into ...
15
votes
1answer
7k views

Uniqueness constraint with date range

Consider a prices table with these columns: id integer primary key product_id integer -- foreign key start_date date not null end_date date not null quantity integer price numeric I'...
15
votes
2answers
2k views

Simultaneous calls to the same function: how are deadlocks occurring?

My function new_customer is called several times per second (but only once per session) by a web application. The very first thing it does is lock the customer table (to do an 'insert if not exists'&...
14
votes
2answers
44k views

psql: FATAL: Peer authentication failed for user

I just installed PostgreSQL 9.4 on Ubuntu 15.10. I created a user with createuser -P myuser I created a database with createdb -O myuser mydatabase I edited pg_hba.conf and added local mydatabase ...
13
votes
4answers
34k views

postgres how to drop all the table in a schema through command

I use postgresql and I need to drop all the tables which are present in the schema. How can I delete from command prompt.
13
votes
1answer
14k views

Get 10th and 90th percentile by customer

I have a table which contains customers and scores (based on different factors, irrelevant in this case; a customer can have multiple scores), which looks like this: customer_id | score | ...
13
votes
1answer
25k views

PostgreSQL: SSL SYSCALL error: EOF detected

First, I've searched for and found several posts relating to this error, and most of them point either to a RAM issue or an SSL issue, I tried overcoming the SSL possibility by adding the sslmode=...
12
votes
3answers
3k views

Fastest way to count how many dates' ranges cover each date from series

I have a table (in PostgreSQL 9.4) that looks like this: CREATE TABLE dates_ranges (kind int, start_date date, end_date date); INSERT INTO dates_ranges VALUES (1, '2018-01-01', '2018-01-31'), ...
11
votes
2answers
3k views

Same function in SELECT and WHERE clause

Beginner question: I have an expensive function f(x, y) on two columns x and y in my database table. I want to execute a query that gives me the result of the function as a column and puts a ...
11
votes
2answers
9k views

Is it recommended to install extensions into pg_catalog schema?

Since objects in pg_catalog schema are implicitly in the search_path (docs), would it be recommended to install extensions in that schema?
11
votes
1answer
6k views

Permission denied to create “pg_catalog.tablename” during pg_dump targetting another machine

I am trying to dump some tables from a 9.5 beta 2 to a 9.4.4 server. The form of the command I am using is the fairly standard: pg_dump -t table dbname | psql -h hostname -d dbname I am using the ...
11
votes
3answers
16k views

set session - custom variable to store user id

I want to store user id in custom session variable and use it (read) in trigger procedures to authorize user actions. I found something like this: set session "myapp.user" = '12345'; ... SELECT ...
10
votes
2answers
16k views

Amazon RDS Postgresql adding new extensions

I want to download jsonbx to RDS instance. RDS PostgreSQL Features Supported shows only built-in features. Does this mean there is no way we can install an extension to RDS which is not in the Feature ...
10
votes
3answers
22k views

Calculate rolling sum over 7 consecutive day period on PostgreSQL

I need to get the rolling sum over a period of 7 days for each row (1 row per day). For example: | Date | Count | 7-Day Rolling Sum | ------------------------------------------ | 2016-02-01 | ...
10
votes
1answer
18k views

how to use index to speed up sorting in postgres

I am using postgres 9.4. The messages has the following schema: messages belongs to feed_id, and has posted_at, also messages can have a parent message (in case of replies). ...
10
votes
1answer
7k views

pgAdmin is extremely slow on any remote operation

I run this query from my local pgAdmin connecting remotely to our dev server: select * from users order by random() limit 1; it hangs for 17 seconds and shows Total query runtime: 148 ms. 1 row ...
10
votes
1answer
6k views

Why is a gin index on a jsonb column slowing down my query and what I can do about it?

Initialize test data: CREATE EXTENSION IF NOT EXISTS pgcrypto; CREATE TABLE docs (data JSONB NOT NULL DEFAULT '{}'); -- generate 200k documents, ~half with type: "type1" and another half with type: "...
9
votes
3answers
15k views

Postgres is performing sequential scan instead of index scan

I have a table with about 10 million rows in it and an index on a date field. When I try and extract the unique values of the indexed field Postgres runs a sequential scan even though the result set ...
9
votes
1answer
9k views

Select rows based on a minimum in one column

Working with PostgreSQL 9.4, I want a result that takes into consideration only min() (all aggregate functions) values of distance on JOIN or WHERE. But its seems those things are not allowed. So, I ...
9
votes
1answer
4k views

What does “Heap Block” in “Bitmap Heap Scan” mean?

I have this query: EXPLAIN (ANALYZE, BUFFERS) SELECT * FROM test WHERE timestamp_range @> '2015-01-22 23:00:00'::timestamp AND data_int_array @> '{49, 61}'::integer[]; Which outputs: ...
9
votes
2answers
11k views

Implementing json_object_agg() in Postgres 9.3

I feel like I need the json_object_agg() function of Postgres 9.4 but I will not be able to upgrade from 9.3 right now. Is there a way to do what I want in 9.3? Here's my scenario. I have a table ...
9
votes
2answers
41k views

“ERROR:malformed array literal” when using json_to_record with a JSON array element in Postgres 9.4

This illustrates the issue nicely: When column b is of type text, and not an array, the following works: select * from json_to_record('{"a":1,"b":["hello", "There"],"c":"bar"}') as x(a int, b ...
9
votes
2answers
20k views

Restoring from pg_dump with foreign key constraints

In restoring a database from a pg_dump, a number of errors are being generated and the whole table is subsequently being ignored. An example: ERROR: insert or update on table "channelproducts" ...
9
votes
1answer
567 views

How to reclaim space taken by an index that partially built and was terminated by a power outage

I'm running postgres (postgis) 9.4.2 on a mac (10.10.4). I've got a couple big tables (several TBs). During an index build on one of them that takes about a week, I watched the available HD space ...
8
votes
5answers
10k views

How is possible to configure TLSv1.1 protocol for SSL connection in PostgreSQL?

I need to configure TLS 1.1 protocol for SSL connection in PostgreSQL. I was not able to see protocol setting in the PostgreSQL configuration It is required to disable SSL protocols and TLSv1 and ...
8
votes
1answer
9k views

Do indexes get transferred with pg_restore

I see other questions that have been answered in the negative (i.e. indexes do not get transferred over with the standard pg_restore). However, it looks like it did in my recent dump/restore and I am ...
8
votes
2answers
19k views

Creating an array from multiple columns without NULL elements

I'm trying to build a query to aggregate together multiple columns in a legacy table stored in a similar structure as below: CREATE TEMPORARY TABLE foo AS SELECT * FROM ( VALUES (1,'Router','...
8
votes
3answers
4k views

CONCAT used in INDEX causes ERROR: functions in index expression must be marked IMMUTABLE

I am facing the following error: ERROR: functions in index expression must be marked IMMUTABLE When trying to create index like this: CREATE INDEX full_phone_number ON orders_clientphone (concat(...
8
votes
1answer
1k views

Do fixed-width rows improve PostgreSQL read performance?

I have a table articles: Table "articles" Column | Type | Modifiers ...
8
votes
1answer
2k views

SELECT DISTINCT ON subquery uses inefficient plan

I've got a table progresses (contains on the order of hundreds of thousands of records currently): Column | Type | Modifiers ...
8
votes
4answers
27k views

Select rows for which at least one row per set meets a condition

I have following table: create table test ( company_id integer not null, client_id integer not null, client_status text, unique (company_id, client_id) ); insert into test values (1, 1, '...
8
votes
2answers
4k views

Removing duplicate rows with two or more left join tables

With a query like this SELECT a.id, a.name, COALESCE( json_agg(b.*), '[]'::json ), COALESCE( json_agg(c.*), '[]'::json ), FROM a LEFT JOIN b ON a.id = b.a_id LEFT JOIN c ON a.id = ...
8
votes
1answer
1k views

How to convert a Postgresql ltree structure to a nested set by using VIEW?

I would like to ask a question about a way for transforming a PostgreSQL ltree structure to a nested set structure with only one query by using only VIEWs. For example, I have a table which has data ...

1
2 3 4 5
11