PostgreSQL is an enterprise class, open-source, object-relational database management system (ORDBMS) available for all major platforms including Linux, UNIX, Windows and OS X. Please mention your exact PostgreSQL version when asking questions.

learn more… | top users | synonyms (1)

0
votes
0answers
12 views

Postgresql : Table historisation

I would like to do a script that gather data from an API everyday. (8000 lines/days) So for each object would like a object1 table for the data of the day. And a object1_hist for archived data. ...
0
votes
1answer
14 views

Returning setof derived from for loop in plpgsql

I have the below function. It is intended to loop through every schema and return all user IDs from a table in that schema. The schemas have the format: users[0-100]. $body$ declare r varchar; ...
0
votes
0answers
22 views

How to create counter for table column (not id) which reset to 1 every month?

I suppose that I need to do something like this: ALTER SEQUENCE product_id_seq RESTART WITH 1 But I want to do this automatically every month.
0
votes
0answers
30 views

Delete data from related Tables with condition

I have Table a (id, id_d); --fk contraints = on delete cascade Table b (id, language_code); Table c (id_a, id_b); --fk contraints = on delete cascade Table d (id); I want to delete an entry from ...
0
votes
0answers
26 views

psql: how to turn off context messages at raise notice

If I use raise notice, I get context messages at each execution. Can I turn them off and just get the NOTICE? NOTICE: d = [2,1] ,tn: (1,2,"{NULL,NULL}","{{-1,4},{-1,-1}}",1) CONTEXT: SQL ...
0
votes
0answers
14 views

How to block messages from Londiste?

This question is part postgres and part londiste. I have successfully upgraded PostgreSQL from 9.1 to 9.3 using Londiste. However, in the PostgreSQL 9.3 log, I am still getting some messages related ...
0
votes
1answer
33 views

Postgresql 9.1 PITR file system base backup - do I need to stop database?

I am preparing for a migration of a big database to another server and plan to use WAL archiving and Point-In-Time-Recovery to minimize downtime. After reading the documentation I learned I have to do ...
0
votes
1answer
28 views

Get statistics of slow running queries

My database application runs many different queries. I have set log_min_duration_statement to 1000. But queries logged there are not always slow, most times they just take a few ms. Is it possible to ...
0
votes
0answers
33 views

Reducing the size of a PostgreSQL Database, utilizing a process other than full VACUUM

We have a Postgres 8.4 installation which hosts both our Defect tracking and Code management (Surround) systems. We are looking at converting and migrating Surround to MSSQL on another server. Our ...
1
vote
1answer
43 views

Join and count boolean columns by logical OR

There are two tables: user_table and user_schedule. Each user has four schedule rows (one for each 6 hour period per day) with one column for every workday. The desired result is to count the number ...
0
votes
1answer
25 views

Grant access to all tables of a database

I recently wanted to share regular access rights with one user of a server and I realized that a simple CREATE USER and GRANT ALL ON DATABASE commands didn't let him run a simple SELECT on the data. ...
1
vote
1answer
54 views

PostgreSQL isn't using indices in FULL OUTER JOIN

I have these tables I'd like to do a FULL OUTER JOIN between. They both have an index on (ts_minute, user_id, campaign_id, host_id) (which matches the join condition). In the following query, if I ...
2
votes
1answer
39 views

INSERT multiple values via join

I have three tables, representing two entities and a connection relationship. Each of the entity relations has an artificial surrogate key used for foreign key constraints in place of natural keys. ...
2
votes
1answer
64 views

How do completely empty columns in a large table affect performance?

I have 400 million rows in a Postgres db, and the table has 18 columns: id serial NOT NULL, a integer, b integer, c integer, d smallint, e timestamp without time zone, f smallint, g timestamp without ...
0
votes
0answers
18 views

How to check if an IP is contained in a list of networks in PostgreSQL?

I have two tables: The first one contains a list of networks and IP-addresses with their IDs and a User-ID, the second one contains log entries with a source address. A given user must only be able to ...
2
votes
1answer
20 views

How can I add a numeric version_id column to an existing table?

I have a table in a postgres db with rows versioned with a timestamp that I'd like to add a numeric version_id column to. eg. existing: ID VERSION_DATE -- ----------------------- A 2015-02-05 ...
0
votes
0answers
16 views

Postgres shared_buffers utilization

Hi is it possible to show how much of the shared_buffers postgres is using or how can i know it is too small?
1
vote
1answer
94 views

Reuse SELECT query by adding results in array?

I have written a PostgreSQL function, which returns a specific order of products. Now I would like, not only to show, but to put the results of the first SELECT query to an array as well, so I can ...
1
vote
2answers
52 views

Reset the sequence of a serial PK with dynamic SQL

How can I dynamically reference a sequence name (as below) using a combination of strings and DECLARE variables? Is the code below proper or is there another method of doing this? My goal is to do ...
0
votes
1answer
37 views

PostgreSQL function thinks table reference exists when it does not

So I run this query: SELECT f_copy_tbl('parts','parts1'); ...while working on code based off of this answer and I get this error message: ERROR: relation "parts1" already exists pgAdmin III ...
0
votes
0answers
14 views

PostgreSQL plpgsql math increment a DECLARE to fix table sequence [duplicate]

The answer to this question will help me post a full (hopefully) working answer to my earlier question about replicating tables and their primary key. I'm new to plpgsql so the context of this ...
1
vote
1answer
70 views

Multi table GROUP BY query optimisation

Currently I have a multi table/column GROUP BY query which is pretty slow. Below is the tables schema used by the query: report Table ...
1
vote
1answer
30 views

Rename the constraint of a possibly referenced primary key in PostgreSQL

Is it safe to use this command just like that, even though the table might be referenced from other tables as foreign key? ALTER INDEX foo_pkey RENAME TO pk__foo__id; I have just tried it and it ...
1
vote
0answers
28 views

Combining date and date/time ranges in PostgreSQL

In a PostgreSQL table, I'd like to store events which have a range telling when the event is happening. However, some events span whole days (i.e., the user does not care about time), while others ...
1
vote
0answers
31 views

Implementing a consistent mailbox

I am trying to implement something like a mailbox for short messages between users. I am using Postgresql 9.4.1 with SQLAlchemy (Python3). There is a table of users: users = Table('users',metadata, ...
0
votes
0answers
14 views

Should I partition table by time or project_id, or both?

I have a table of event data that is getting slightly large. It's ~10 million records. I want to partition the table to help speed things up. I almost always restrict the query by both the time and ...
1
vote
3answers
89 views

Copy table with separate sequences for serial columns

While creating a column management tool I came across the need to quickly replicate tables in PostgreSQL so I would not test new tools with non-test tables. To effectively test the new column tool ...
0
votes
1answer
29 views

PostgreSQL utilize data from SELECT in BEGIN or use WITH?

I went through the documentation for 9.3 and did not find anything suggesting that I can or can not use data from a SELECT query within a BEGIN query. Is it possible or will I have to resort to a WITH ...
0
votes
0answers
23 views

Better way to create an Events table?

I working on a medium sized PostgreSQL database with some schemas, each with some tables. In almost every schema there are tables that represent event tables, where something that has "happened to" ...
0
votes
0answers
12 views

How to add entries to tables in PostgreSQL if the attributes are reliant on other tables?

The problem that I have is something like this: Users ========= UserID Name Surname User Group ========= GroupID LeaderID Group Leaders ============= LeaderID UserID GroupID The problem arises ...
-1
votes
1answer
60 views

is camel case for column names safe?

I have a database where column names are all camel cased. No problems encountered. Will that be a problem under some scenarios, as per recent versions of MySQL, Postgres?
0
votes
2answers
111 views

check key if exists in other table without fk constraint

Lets say i have: table a (id_a int); table b (id_b int, id_a int); I want to check if b.id_a exists in "a" before a new row in "b" will be inserted. Normally I would just add a fk constraint on ...
0
votes
1answer
51 views

Connect to remote EC2 Postgresql database

I want to setup a connection between a webserver and a PostgreSQL 9.3 server. Both are hosted on Amazon EC2 servers and are part of the same security group. I can't get the connection working. The ...
1
vote
1answer
23 views

PostgreSQL : Where is index kept until check point occures ?

In PostgreSQL data is first written to WAL files. When commit is done, data is written to WAL files and then return to client (synchronous commit). When checkpoint reached or WAL buffer becomes full, ...
2
votes
1answer
40 views

Storing floating point values for various units of measurement (kg, ml, mm, pl)

I have a table like the following: order_item ------------ serial | id (PK) integer | order_id ???? | quantity integer | unit_of_measure_id (PK) --> ml, l, kg, mg, mm, m, etc. ...
1
vote
1answer
33 views

How can I share pg_dump output with my team so they can restore without errors?

I am on a team that is building a Drupal website. All of the settings, including the migration scripts from the old site, will be in code, so in theory all of our work can be replicated just from a ...
2
votes
2answers
74 views

How can one optimize a query involving a sort and a LIKE?

Here is the query: EXPLAIN ANALYZE SELECT * FROM "Users" AS "User" WHERE "User"."name" LIKE 'garr%' AND "User"."id" NOT IN (2449214) AND "User"."hellbanned" IS NULL AND ...
0
votes
1answer
44 views

Is it possible to make database owner read only?

The database owner can revoke certain privileges from themselves such as INSERT but is it possible to revoke further privileges such as DROP for read-only operation?
2
votes
1answer
34 views

Does READ COMMITTED always start over after serialization failures while SERIALIZABLE simply fails?

On the PostgreSQL Concurrency With MVCC page, it says: know what you’re thinking though: what about a two transactions updating the same row at the same time? This is where transaction isolation ...
0
votes
0answers
34 views

How calculate per tenant disk usage in a multitenant database with tenant_id columns?

I would like to provide forum hosting as a service, for forum software I'm developing. The data is stored in a PostgreSQL database, in tables with a forum_id column. That is, all forums share the same ...
1
vote
2answers
75 views

Is it safe to cancel a PostgreSQL ALTER TABLE query that is waiting on a lock?

We started an ALTER TABLE query hours ago and only recently realized (via pg_stat_activity) that it is waiting on a lock. We discovered the other query that is holding a lock on the table we want to ...
2
votes
0answers
59 views

Optimizing a single table, write-once, read-many PostgreSQL database

I've just finished constructing a table of ~835 million rows using Google's ngram dataset, aggregated on the years in which they occurred so that each 2-,3-,4-, and 5-gram is represented by a single ...
0
votes
0answers
43 views

Postgres user without password

I'm creating unit tests on a python application that uses digital certs on the server. Since I am not testing the connection between the server and the database, I need to setup the temporary test ...
0
votes
1answer
27 views

Query performance with primary keys of different data types

Is there a significant difference in performance if i decide to use INT or BIGINT as data type of a primary key in a table? Of course if i use BIGINT the value will have twice it's size. But as the ...
0
votes
1answer
34 views

How to know when Postgresql password is changed

My question is how to know the date when a postgresql user password is changed. Is it possible? I know postgresql has account expiry feature, but I'm asked to check if users have changed their ...
0
votes
2answers
69 views

Optimizing a Postgres query with a large IN

This query gets a list of posts created by people you follow. You can follow an unlimited number of people, but most people follow < 1000 others. With this style of query, the obvious optimization ...
1
vote
0answers
71 views

Database performs differently on the two same Xeon E3 1270-v3 Quad Core machines [closed]

Configuration: RAM: 16 GB DDR3. HDD: Seagate 500 GB 7200 3Gb/s 3.5 inch SATA - idential disks. Postgres 9.4, tried with 9.4.1 also Windows 2008 R2 Web Tried these tunings: work_mem = 32MB ...
0
votes
0answers
40 views

Append elements to array only if the element does't exist

WITH upd AS ( UPDATE univ.products SET source = source::int[] || _source WHERE project_id = _project_id AND product_id = _products AND NOT(_source = ANY(source)) RETURNING id ) , ins AS ( ...
-1
votes
1answer
27 views

Postgresql - Stuck building a plpgsql function [closed]

I am a beginner in plpgsql and i am stuck coding a function. I need a function that does the following: Giving a table, a id_field in that table and another field in that table it does: ORIGINAL ...
1
vote
1answer
52 views

PostgreSQL Replication on a daily basis

With PostgreSQL, I want to replicate a subset of all tables from Database A to B, but only once a day. Since I do not know what to search for: is there a technical term for such a scenario? Does e.g. ...