Programming

PostgreSQL

What is PostgreSQL?

PostgreSQL comes from Michael Stonebraker's POSTGRES work at Berkeley. The open form that speaks SQL took the name PostgreSQL in 1996. The short name is Postgres. The program runs on its own, and its port is usually 5432. You connect to it, open a table, write a row, and read by a condition. The data stays on disk. When the machine turns off and on, a written row does not vanish. It does not hand you that as one .db file. A backup is taken with a separate command.

What is PostgreSQL used for?

PostgreSQL is for data that many people write at the same time. An order, a user, and an account are its place.

  • Keeping a site's user list
  • Writing an order row by row
  • Letting several programs read the same table
  • Writing a conditional query for a report

What can you do with PostgreSQL?

With PostgreSQL you create a table, add a row, and choose. It does not draw a page and it does not run Python. A program sends it a query, and it returns the answer. When many people write, it keeps a turn so two people do not spoil the same row. Do not leave it open without a password. Do not open it to everyone from the network either.

Is PostgreSQL hard to learn?

Opening one table is easy. The difficulty is the connection and the query. When the user or the port is wrong, the program cannot connect at all. Pasting a user's text into the query opens injection. Reading a large table without a condition becomes slow. If a backup is not taken, a disk error takes the rows away. A query written for MySQL may not work here with every word.

Advantages and limits

Advantage: many people can write, the data stays on disk, and the query is strong. Limit: the server has to be set up and guarded. PostgreSQL is not MySQL and it is not SQLite.

Basic ideas

A table is the names of the columns. A row is one record. The server is the program that keeps that table open.

  • It runs as its own process
  • The port is usually 5432
  • An SQL query chooses rows
  • A backup is not taken by itself

A short example

This query opens one table. The server must already be running. You do not create the file by hand.

CREATE TABLE reader (
  id integer PRIMARY KEY,
  name text
);

Common questions

  • Are PostgreSQL and MySQL the same? No. Both are SQL servers. The program is separate, and every query word may not work the same.
  • Are PostgreSQL and SQLite the same? No. SQLite is one file and does not open a separate server. PostgreSQL runs in its own process.
  • Is Postgres another database? No. Postgres is the short name of PostgreSQL.