« PostgreSQL » : différence entre les versions

De Banane Atomic
Aller à la navigationAller à la recherche
Ligne 45 : Ligne 45 :
# switch to the PostgreSQL user
# switch to the PostgreSQL user
sudo -iu postgres
sudo -iu postgres
# create the cluster directory if needed
sudo mkdir /var/lib/postgres
sudo chown postgres:postgres /var/lib/postgres


# initialize the database cluster
# initialize the database cluster
initdb -D /var/lib/postgres/data
initdb -D /var/lib/postgres/data
# $LANG (en_US.UTF-8) is used to deduce the locale and the encoding
# $LANG (en_US.UTF-8) is used to deduce the locale and the encoding
# or can be defined manually: --locale=en_US.UTF-8 -E UTF8
# or can be defined manually:
initdb --locale=C.UTF-8 --encoding=UTF8 -D /var/lib/postgres/data --data-checksums


# start the service
# start the service

Version du 23 mai 2023 à 21:39

Links

Database

Bash.svg
# create a database
createdb myDatabaseName

# connect to a database
psql -d myDatabaseName
Pgsql.svg
-- connect to a database
\c myDatabaseName

Table

Pgsql.svg
-- show summary information about all tables in the current database
\dt

Users and permissions

Pgsql.svg
-- list all users and their permission levels
\du

Service

Bash.svg
sc-start postgresql.service

Installation

Bash.svg
# will install postgresql-libs, postgresql and create a system user called postgres
sudo pacman -S postgresql

Configuration

Bash.svg
# switch to the PostgreSQL user
sudo -iu postgres

# create the cluster directory if needed
sudo mkdir /var/lib/postgres
sudo chown postgres:postgres /var/lib/postgres

# initialize the database cluster
initdb -D /var/lib/postgres/data
# $LANG (en_US.UTF-8) is used to deduce the locale and the encoding
# or can be defined manually:
initdb --locale=C.UTF-8 --encoding=UTF8 -D /var/lib/postgres/data --data-checksums

# start the service
sc-start postgresql.service

# create a user
# If the new user has the same name as your Linux user, it allows you to access the PostgreSQL database shell without having to specify a user to login.
createuser --interactive