postgresql-8.4

Using psql to connect to postgresql in ssl mode

强颜欢笑 提交于 2019-12-02 16:56:19
I am trying to configure ssl certificate for postgreSQL server. I have created a certificate file (server.crt) and key (server.key) in data directory and update the parameter SSL to "on" to enable secure connection. I just want only the server to be authenticated with server certificates on the client side and dont require the authenticity of client at server side. I am using psql as a client to connect and execute the commands. I am using PostgreSQL 8.4 and linux. I tried with the below command to connect to server with ssl enabled psql "postgresql://localhost:2345/postgres?sslmode=require"

Filter by date range (same month and day) across years

ⅰ亾dé卋堺 提交于 2019-12-01 17:13:58
I have a PostgreSQL database with a table holding dates. Now I need to find all rows within the date range 15/02 until 21/06 (day/month) across all years. Example result: 1840-02-28 1990-06-21 1991-02-15 1991-04-25 1992-05-30 1995-03-04 1995-04-10 2001-02-03 2010-04-06 Assuming (with a leap of faith) that you want dates between certain days of the year regardless of the year (like if you're sending out a batch of birthday cards or something), you can set up a test with this: CREATE TABLE d (dt date); COPY d FROM STDIN; 1840-02-28 1990-06-21 1991-02-15 1991-04-25 1992-05-30 1995-03-04 1995-04

Jump SQL gap over specific condition & proper lead() usage

故事扮演 提交于 2019-12-01 12:18:57
(PostgreSQL 8.4) Continuing with my previous example , I wish to further my understanding of gaps-and-islands processing with Window-functions. Consider the following table and data: CREATE TABLE T1 ( id SERIAL PRIMARY KEY, val INT, -- some device status INT -- 0=OFF, 1=ON ); INSERT INTO T1 (val, status) VALUES (10, 0); INSERT INTO T1 (val, status) VALUES (11, 0); INSERT INTO T1 (val, status) VALUES (11, 1); INSERT INTO T1 (val, status) VALUES (10, 1); INSERT INTO T1 (val, status) VALUES (11, 0); INSERT INTO T1 (val, status) VALUES (10, 0); As previously explained, the devices turn ON and OFF

GeoServer won't write to my PostgreSQL updateable view

梦想与她 提交于 2019-12-01 11:20:58
Following on from this earlier question I'm on PostgreSQL 8.4 and am having trouble with updatable views. I have a view: CREATE VIEW filedata_view AS SELECT num, id, ST_TRANSFORM(the_geom,900913) AS the_geom FROM filedata And want to update it from my application throw Geoserver. But get a error: <ServiceExceptionReport version="1.2.0" xmlns="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd"> <ServiceException> {http://www.opengeospatial.net/cite}filedata_view

PostgreSQL - inconsistent COPY permissions errors

ε祈祈猫儿з 提交于 2019-12-01 07:48:44
问题 I am using the EnterpriseDB pgAdmin III (v. 1.12.1) on a Windows 7, 32-bit machine to work with PostgreSQL databases on a remote Linux server. I am logged in as the user postgres, which allows me to access the $PGDATA directory (in this instance, it is found here: /var/lib/pgsql/data/) If I log into the server via a terminal, run psql, and use the \copy command to import data from csv files into newly created tables, I have no problems. If I'm in pgAdmin, however, I use the COPY command to

PostgreSQL: Add Interval to Timestamp from column value

若如初见. 提交于 2019-11-30 22:28:41
问题 I need to add minutes coming from an integer column with a timestamp to compare to another column. Here's an example: SELECT t1.id_liame, t1.id_table, t1.periodicidade , t3.data_extracao, CASE WHEN(NOW() < (e.data_extracao + INTERVAL t1.periodicidade || ' MINUTES')) THEN 'yes' ELSE 'no' END FROM table1 as t1 LEFT JOIN liame_has_extracao as t2 USING(id_liame) LEFT JOIN extracao as t3 USING(id_extracao) l.periodicidade is integer (minutes) I need to verify if data_extracao(timestamp) is greater

Analysing/Profiling queries on PostgreSQL

我只是一个虾纸丫 提交于 2019-11-30 13:57:50
I've just inherited an old PostgreSQL installation and need to do some diagnostics to find out why this database is running slow. On MS SQL you would use a tool such as Profiler to see what queries are running and then see how their execution plan looks like. What tools, if any, exist for PostgreSQL that I can do this with? I would appreciate any help since I´m quite new with Postgres. Use pg_stat_statements extension to get long running queries. then use select* from pg_stat_statements order by total_time/calls desc limit 10 to get ten longest. then use explain to see the plan... Chris

How to create an “on-the-fly” mapping table within a SELECT statement in Postgresql

江枫思渺然 提交于 2019-11-30 12:45:17
I'm creating a select statement that combines two tables, zone and output , based on a referenced device table and on a mapping of zone_number to output_type_id . The mapping of zone_number to output_type_id doesn't appear anywhere in the database, and I would like to create it "on-the-fly" within the select statement. Below is my schema: CREATE TABLE output_type ( id INTEGER NOT NULL, name TEXT, PRIMARY KEY (id) ); CREATE TABLE device ( id INTEGER NOT NULL, name TEXT, PRIMARY KEY (id) ); CREATE TABLE zone ( id SERIAL NOT NULL, device_id INTEGER NOT NULL REFERENCES device(id), zone_number

Select today's (since midnight) timestamps only

ⅰ亾dé卋堺 提交于 2019-11-30 07:45:04
问题 I have a server with PostgreSQL 8.4 which is being rebooted every night at 01:00 (don't ask) and need to get a list of connected users (i.e. their timestamps are u.login > u.logout ): SELECT u.login, u.id, u.first_name FROM pref_users u WHERE u.login > u.logout and u.login > now() - interval '24 hour' ORDER BY u.login; login | id | first_name ----------------------------+----------------+------------- 2012-03-14 09:27:33.41645 | OK171511218029 | Alice 2012-03-14 09:51:46.387244 |

How to create an “on-the-fly” mapping table within a SELECT statement in Postgresql

与世无争的帅哥 提交于 2019-11-29 17:25:42
问题 I'm creating a select statement that combines two tables, zone and output , based on a referenced device table and on a mapping of zone_number to output_type_id . The mapping of zone_number to output_type_id doesn't appear anywhere in the database, and I would like to create it "on-the-fly" within the select statement. Below is my schema: CREATE TABLE output_type ( id INTEGER NOT NULL, name TEXT, PRIMARY KEY (id) ); CREATE TABLE device ( id INTEGER NOT NULL, name TEXT, PRIMARY KEY (id) );