Quantcast
Channel: Question and Answer » postgresql
Browsing all 1138 articles
Browse latest View live

How to schedule the daily backup of a specific database in PostgreSQL?

I have a database ‘ahrims’, I want to schedule PostgreSQL under linux to backup this specific database (not all databases) at 4:00 PM daily. How can I achieve this? Please help!

View Article


Postgres sharding installation with citusdb

We are developing a prototype for a BIG data product. We have almost 2 billion records. We have used PostgresSQL 9.5 as a back-end and Python as front-end. We are using a 16*2.4 GHz processors with 160...

View Article


How can I improve this nested postgresql query?

I have a mildly complex query that is having rather poor performance: UPDATE web_pages SET state = 'fetching' WHERE web_pages.id = ( SELECT web_pages.id FROM web_pages WHERE web_pages.state = 'new' AND...

View Article

PostgreSQL: Slow JOIN on three large tables

Edit: Proposed this question as a LEFT JOIN problem, but as @wildplasser pointed out, due to my WHERE clause I was actually doing a JOIN all along. Adjusting the question from LEFT JOIN to JOIN. The...

View Article

How can I dump all tables to CSV for a PostgreSQL schema?

I have a database with a lot of schemas in it and I want to dump the each of the table contents to CSV. I’m aware of the COPY command but I’m not sure how to script something that will read all of the...

View Article


Profiling postgres with gprof: no data/gprof folder and 'no time accumulated'

I’m attempting to profile Postgres with gprof. A gmon.out file successfully gets created in both the data directory and in the working directory where I launched the client (pgbench) process from....

View Article

Using sub-query column in where clause

This question has been asked several times and even answered as well but it’s not helpful to me, that’s why I am posting it again. I have this query: select u.*,l.*, ( select count(cr.id) from...

View Article

PostgreSQL not running every update on my script

I’m running a dozen update statements on a loop and some updates just won’t happen (they return 0 affected rows), If i recall the script it will slowly update the rows, I don’t know how to debug this....

View Article


Constraint on row value based on values in other rows

Is it possible to have a table with four columns: CREATE TABLE accrual ( add_date date NOT NULL, user_id integer NOT NULL, rate integer NOT NULL, amount numeric(7,3) ); and then constrain it so that if...

View Article


Image may be NSFW.
Clik here to view.

pg_stat_activity shows lots of easy queries running for minutes

After application server start its connection pool fills quickly and application can’t work properly. I went through pg_stat_activity and noticed lots of queries running for minutes: But postgres’s...

View Article

Very different query plans with and without LIMIT in PostgreSQL.

I have the following query which I am using to create vector tiles for a web map. I’m pulling together just the geometries within the selected tile using a CTE, then joining it to get additional...

View Article

insert/update from web server or database

I have a data-model on the front-end that I want to insert/update in the database which of the following approaches (or neither!) is considered best practice: # in webserver some_model = {json}...

View Article

Foreign key with additional constraints?

There is a table called Item(id, name, cost) and Orders(id, bill_id, item_id, units), which is created to track orders placed, where same bill_id means it belongs to a single order. How to impose an...

View Article


Dynamic Column Label in Postgres 9.5

I am using postgres 9.5 and have built the following function: CREATE or REPLACE FUNCTION func_getratio_laglag(_numeratorLAG text, _n1 int, _denominatorLAG text, _n2 int, _table text) RETURNS TABLE...

View Article

Reuse subquery as in another result

In a typical social-network-like application I have the following query that gathers news from a set of followed channels. The main query gets the news, while the subquery gets the followed channels:...

View Article


Converting standard_conforming_strings from off to on when importing Postgres...

I’ve got a Postgres 8.1 instance which has standard_conforming_strings set to off (== handles slashes as escape characters). Recent Postgres versions have this setting on by default (for good reasons)....

View Article

Make a (copy of a) postgis database available to customer?

Our application uses a PostgreSQL database (with the PostGIS spatial extension). Now one of our customers has requested direct access to the database; because, as they claim, it’s their data. We’d...

View Article


best way to avoid redundant aggregate functions and/or group by columns

Suppose I have two tables: Foo: id baz Bar: id foo_id boom So a Foo has many Bars. I frequently find myself in situations where I need to compute an aggregate across the Bars for a given set of Foos...

View Article
Browsing all 1138 articles
Browse latest View live