postgresql

Topics related to postgresql:

Getting started with postgresql

This section provides an overview of what postgresql is, and why a developer might want to use it.

It should also mention any large subjects within postgresql, and link out to the related topics. Since the Documentation for postgresql is new, you may need to create initial versions of those related topics.

JSON Support

Role Management

Common Table Expressions (WITH)

Accessing Data Programmatically

Backup and Restore

Backing up the filesystem instead of using pg_dumpall and pg_dump

It's very important that if you use this, you call the pg_start_backup() function before and pg_stop_backup() function after. Doing filesystem backups is not safe otherwise; even a ZFS or FreeBSD snapshot of the filesystem backed up without those function calls will place the database in recovery mode and may lose transactions.

I would avoid doing filesystem backups instead of regular Postgres backups, both for this reason, and because Postgres backup files (especially in the custom format) are extremely versatile in supporting alternate restores. Since they're single files, they're also less hassle to manage.

Table Creation

INSERT

UPDATE

Dates, Timestamps, and Intervals

Aggregate Functions

Programming with PL/pgSQL

PL/pgSQL is PostgreSQL's built-in programming language for writing functions which run within the database itself, known as stored procedures in other databases. It extends SQL with loops, conditionals, and return types. Though its syntax may be strange to many developers it is much faster than anything running on the application server because the overhead of connecting to the database is eliminated, which is particularly useful when you would otherwise need to execute a query, wait for the result, and submit another query.

Though many other procedural languages exist for PostgreSQL, such as PL/Python, PL/Perl, and PLV8, PL/pgSQL is a common starting point for developers who want to write their first PostgreSQL function because its syntax builds on SQL. It is also similar to PL/SQL, Oracle's native procedural language, so any developer familiar with PL/SQL will find the language familiar, and any developer who intends to develop Oracle applications in the future but wants to start with a free database can transition from PL/pgSQL to PL/SQL with relative ease.

It should be emphasized that other procedural languages exist and PL/pgSQL is not necessarily superior to them in any way, including speed, but examples in PL/pgSQL can serve as a common reference point for other languages used for writing PostgreSQL functions. PL/pgSQL has the most tutorials and books of all the PLs and can be a springboard to learning the languages with less documentation.

Here are links to some free guides and books on PL/pgSQL:

Inheritance

PostgreSQL High Availability

Triggers and Trigger Functions

EXTENSION dblink and postgres_fdw

Window Functions

Postgres Tip and Tricks

Backup script for a production DB

  1. If there is a backup tool such as HDPS, or Symantec Backup, ... It is necessary to empty the backup directory before each launch.

To avoid cluttering the backup tool because the backup of old files is supposed to be done.

To enable this feature please uncomment line N° 3.

rm -R / save_db / *
  1. In the case where the budget does not allow to have a tool of backup, one can always use the tasks planner (cron command).

The following command is used to edit the cron table for the current user.

crontab -e

Schedule the launch of the script with the calendar at 11pm.

0 23 * * * /saveProdDb.sh

Comments in postgresql

Export PostgreSQL database table header and data to CSV file

Data Types

Recursive queries

Postgres cryptographic functions

Event Triggers

SELECT

Connect to PostgreSQL from Java

Find String Length / Character Length

COALESCE