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
1 view

How do I make this Postgres view that performs a join updatable?

I've got two tables, products and subscriptions: CREATE TABLE products ( id bigint NOT NULL, title character varying(75), description text, manufacturer_id bigint, created_at ...
2
votes
1answer
10 views

Single table or multiple table design when records have a clear distinction but are queried together?

Let's say I have the following types of recurring data (all types periodically come in). Post (Title, Summary, Text, Timestamp) Image (URL, Caption, Timestamp) Event (StartDate, EndDate, Title, ...
4
votes
0answers
32 views

Postgres: Is migrating old records to separate table and creating new aggregated records a good strategy to improve search speed?

I have a table with 1M+ records. New records are created and updated each day each time an event occurs for each type of event (which there are many). I frequently need to find sums across many ...
1
vote
1answer
12 views

RETURN TABLE is converted to RETURN SETOF int in Postgres function

In pgAdminIII I create a function that returns multiple rows in a single column named identifier using RETURN TABLE: CREATE OR REPLACE FUNCTION test( IN parm1 date, IN parm2 interval) ...
4
votes
1answer
34 views

Select a count with some conditions

Using Postgres 9.4, I have a table page_views which has a page column. I'd like to select all the distinct pages and have a count before them and sort them descending. I'd also like to have a minimum ...
2
votes
0answers
24 views

How to do Statistics in Partial Indexes of PostgreSQL efficiently?

This answer motivated think again my following tables but I am still uncertain how to store statistic data for quick selection. I think it is well done with partial indexes because only a subset of ...
1
vote
2answers
21 views

Postgresql: Insert trigger function fails on partial insert statement

We have some big tables in our database and the boss thought that partitioning would be a good improvement to our system. I was charged to investigate it and develop all the needed scripts in a test ...
0
votes
0answers
22 views

Automatic failover mechanism for PostgreSQL

I need to have a automated failover setup in my production environment for postgres DB. Though I have explored various articles/blogs to achieve the same, I am not fully convinced on the methods ...
1
vote
1answer
84 views

Does PostgreSQL support online schema modification (DDL)?

Recent versions of MySQL (using InnoDB) support many alter table queries without exclusive locking the table. Does PostgreSQL support this to any level? That is, can I add/drop columns from a table ...
-2
votes
1answer
24 views

Like operator in postgresql [on hold]

how to check the reverse of the original word using like operator? For Eg: victoria state------state victoria This is the query i tried: SELECT DISTINCT ON (t1.name) ...
5
votes
1answer
33 views

Naming conflict between function parameter and result of JOIN with USING clause

Given this setup in current Postgres 9.4 (from this related question): CREATE TABLE foo (ts, foo) AS VALUES (1, 'A') -- int, text , (7, 'B'); CREATE TABLE bar (ts, bar) AS VALUES (3, 'C') ...
3
votes
1answer
35 views

How to get the difference in days between 2 timestamps in PostgreSQL

I have a table named accounts. I am interested in retrieving those accounts whose status has not been updated since more than 10 days. I thought about this query and it seemed to work but I am not ...
4
votes
1answer
41 views

Truncate parent table but not children

I have a table in PostgreSQL 9.4 that I partitioned so that all inserts to the parent actually go into one of the child partitions. The problem is that I already have hundreds of millions of rows of ...
2
votes
1answer
22 views

Find substrings within between 2 string fragments

I am trying to populate a view in PostGIS in Postgres 9.0 and in this view I want it to contain a substring based on 2 string positions. See below for my code. CREATE OR REPLACE VIEW vw_actions AS ...
0
votes
1answer
27 views

PostgreSQL database connection time [on hold]

how to check how much time PostgreSQL database takes for making connection?
6
votes
1answer
35 views

How can I combine two event tables into a single timeline, in PostgreSQL?

Given two tables: CREATE TABLE foo (ts timestamp, foo text); CREATE TABLE bar (ts timestamp, bar text); I wish to write a query that returns values for ts, foo, and bar that represents a unified ...
4
votes
3answers
32 views

Use trigger to synchronize columns with fields in json column on insert or update

I'm a bit of a database/postgres beginner,so bear with me. If I have a table, something like this. CREATE TABLE testy ( id INTEGER REFERENCES other_table, name varchar(128) PRIMARY KEY, ...
1
vote
1answer
26 views

how to convert a master cluster to a slave cluster?

I am learning about PostgreSQL streaming replication and so far I have learned how to create a slave cluster using: pg_basebackup -x -R -D main -h host -p port I also have learned that I can ...
0
votes
0answers
19 views

When does pg_dump not export CREATE EXTENSION?

I have a production database that I am trying to dump then load (in plain text format) locally. The problem is, the database being dumped uses the hstore extension in several tables, and contrary to ...
0
votes
0answers
20 views

Getting TEXT data from postgres throught linked server to MSSQL

I'm using MSSQL 2008 R2 with linked server to postgres 9.4. My problem is: when I select column with data type text it shows me only XXX first chars and adds (...) on the end. select description from ...
0
votes
0answers
26 views

PostgreSQL becomes very slow after heavy utilization

I have built a Python web application and I am hosting it in a 2GB RAM Debian Server. My application uses PostgeSQL 9.1 with PostGIS. One of my tasks involves importing data from big csv files. ...
1
vote
0answers
25 views

Is there a way to determine if a postgres function depends on a user-defined type?

I am writing a Ruby script to handle functions and user-defined types in Postgres. I want to make sure, that before a function is created in the database, if it uses a user-defined type, than this ...
2
votes
2answers
42 views

Locking issues under transaction on Postgres

I recently got a "Out of shared memory - You might need to increase max_locks_per_transaction" error. This is a long running process where I import a bunch of CSV files after proper processing. I ...
1
vote
1answer
30 views

Copying CSV file to temp table with dynamic number of columns?

I am wondering if there is a way to copy a csv file into a temp table where the number of columns is unknown in the csv file. The DB software I'm using is PgAdmin III. I figured out that if I do know ...
5
votes
3answers
157 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 ...
2
votes
1answer
42 views

Postgres 9.4+: JSONB instead of EAV

I'm figuring out a way to structure a new postgresql database, and I'm curious if I could use a JSONB column instead of the EAV model for storing properties of an entity. This seens like a flexible ...
1
vote
0answers
43 views

Connection refused when inserting

Description: Machine 1: Linux, PostgreSQL 9.3, on local, 10.12.10.123 Machine 2: Linux, PostgreSQL 9.3, on cloud, 104.10.124.123 Configuration (on both): + postgresql.conf : listen_addresses ="*" + ...
3
votes
1answer
100 views

Leap second in Database system (Postgresql and SQL Server)

This night will be longer because of leap second: https://en.wikipedia.org/wiki/Leap_second My impact will be minimal in my case, I don't even know if I will recive some weird data like 20150630 ...
0
votes
0answers
27 views

Column doesn't exist in PostgreSQL View [on hold]

I have the below situation but I don't get what is the problem with my code. I receive this error: column vx1 doesn't exist. vx1 double precision; vy1 double precision; vz1 double ...
0
votes
0answers
29 views

What order do foreign key constraints run in? Why does my foreign key not work after import?

I have two tables tags and tag_memberships in a PostgreSQL database. On the tag_memberships table, I have two constraints. The first is this: ALTER TABLE tag_memberships ADD CONSTRAINT ...
2
votes
1answer
78 views

Subquery magic in PostgreSQL

I have a query: update product_product set (write_date, default_code) = (LOCALTIMESTAMP, 'update') where product_tmpl_id in ( select distinct product_tmpl_id from product_template ...
0
votes
2answers
58 views

Minimizing SELECT latency in PostgreSQL

I am evaluating Postgres 9.4 performance on a machine with Intel i7 quad-core 3.6 GHz CPU, 8 GB ram, and 7400 rpm HDD (no RAID) running Linux Mint. The DB schema has the following table: ...
0
votes
2answers
58 views

Would like to know why this query is behaving this way?

I have an emp table, with schema and some initial values like below: emp_id | name | last_name | role_id --------+------+-----------+--------- 1 | hell | bell | 1 2 | well | ...
2
votes
1answer
48 views

PostgreSQL doesn't log

I'm using ArchLinux and PostgreSQL 9.4.4 and have enabled the logging in the config file: $ sudo egrep -v "^[[:blank:]]*($|#|//|/\*| \*|\*/)" /var/lib/postgres/data/postgresql.conf max_connections = ...
2
votes
1answer
37 views

Can column uniqueness be commutative?

I have a table in a Postgres DB where col1 and col2 are foreign keys referring to the same column. I want only unique combinations of (col1, col2), i.e. if (1,2) is entered then (2,1) should be ...
0
votes
0answers
31 views

Database migration stops halfway through

I've had issues trying to use PostgreSQL so changed my application to use MYSQL. But, when I run rake db:migrate I get the following message before the migration stops: -- PostgreSQL database ...
4
votes
2answers
182 views

How to speed up ORDER BY sorting when using GIN index in PostgreSQL?

I have a table like this: CREATE TABLE products ( id serial PRIMARY KEY, category_ids integer[], published boolean NOT NULL, score integer NOT NULL, title varchar NOT NULL); A product ...
1
vote
1answer
41 views

Index on colum with data type citext not used

In PostgreSQL 9.4, with following schema: CREATE TABLE people ( id INTEGER PRIMARY KEY, name TEXT, junk CHAR(1000) ); INSERT INTO people(id, name) SELECT generate_series(1,100000), ...
0
votes
1answer
23 views

Kibana-like tool for PosgreSQL [closed]

I'm looking for a tool that could browse and visualize data from db like Kibana does. I'd prefer a native Posgres tool to any that transfers data from a db somewhere else. I know that rivers for ...
1
vote
0answers
19 views

Creating a unique index on a materialized view with no unique columns?

I am using Postgres 9.4. I have created a materialized view from one of my tables and I want to be able to refresh it concurrently. I know from the documentation that in order to do a concurrent ...
1
vote
1answer
18 views

Select Distinct on subset of columns, name different set of columns to return

I am using PostgreSQL and have two tables: Table_A colA | colB | colC | colD | colE | colF | colG | colH | colI | colJ Table_B colA | colB | colC | columnD | colE | columnF | colG | colH | colI | ...
0
votes
1answer
13 views

How to use PostgreSQL bit_or function to aggregate column?

I wish to use PostgreSQL's bit_or function on several rows of a single column of my table, but I can't figure out the proper usage for this. Suppose I have bitwise flags in my column flags, and the ...
0
votes
1answer
27 views

Use PL/pgSQL in PostgreSQL outside of a stored procedure or function?

I'd really like to use an IF, ELSE construct and execute multiple statements within the IF and ELSE blocks, but I don't wish to save my commands to the database as a stored procedure or function. Can ...
1
vote
1answer
25 views

Add a new collation to a Postgres database

I have these collations: postgres=# select * from pg_collation; collname | collnamespace | collowner | collencoding | collcollate | collctype ...
0
votes
0answers
13 views

I am installing postgres-xl. While initializing the coordinator, i am getting the error below [closed]

loading PL/pgSQL server-side language ... FATAL: could not open extension control file "/usr/local/share/postgresql/extension/plpgsql.control": No such file or directory STATEMENT: CREATE ...
2
votes
1answer
35 views

`chown -R` equivalent for PostgreSQL

We occasionally have the problem that, when upgrading some software and database, inexperienced (or overworked, not excluding myself) sysadmins (we don’t have separate DBAs except for Oracle) run the ...
2
votes
2answers
83 views

How to review Database schema?

I am green been software engineer, my team lead give me a task in PostgreSQL database, I need to determine the relationship of the all 405 tables, but the problem is the database doesn't have any ...
-1
votes
3answers
68 views

Why does connecting to '127.0.0.1' work whilst 'localhost' fails?

I have noticed that although the listening host in postgresql.conf is localhost connecting to a database via psql fails unless the host is changed 127.0.0.1. I have also noticed MySQL display the ...
0
votes
0answers
24 views

PostgreSQL: pgbouncer cannot connect to server

I have PG 9.4 running on a given CentOS host: host1, and pgbouncer 1.5.5 running on another CentOS host: host2. Once an hour, some CSV files are downloaded automatically on host2 and loaded into PG ...
1
vote
2answers
189 views

PostgreSQL : avoid SUM over same values multiple times

I've a student table and a table of scores in various subjects. I want to sum score1 & score2 for each student across all subjects and then add the bonus for each student. CREATE TABLE student ( ...