PostgreSQL is an open-source object-relational database management system. It is known for its reliability, scalability, and extensive functionality, including JSON support, full-text search, stored procedures, extensions, and more.
With Hostman managed PostgreSQL databases, you get a fully managed PostgreSQL cluster without manual setup: everything is handled automatically.
When creating a cluster, you can select the PostgreSQL version: 14, 15, 16, 17, 18.
When you create a new cluster, a database named default_db
is created automatically.
You can create additional databases:
Go to the Databases section of your Hostman control panel.
Click on the cluster.
In the Databases tab, click Add.
Provide a name for your database: 3–64 characters. Letters, numbers, and special characters are allowed.
Add a description, if necessary.
Click Create.
In your control panel, you can manage PostgreSQL users and their privileges.
Go to the Databases section and click on the cluster.
Open the Users tab and click Add.
Set the username and password:
Username: 3–64 characters. Letters, numbers, and special characters are allowed.
Password: 8–30 characters. Letters, numbers, and special characters are allowed.
(Optional) Configure the user’s privileges. You can also leave the default parameters and change them later at any time.
Click Create.
To update the privileges of an existing user:
Go to the Databases section and click on the cluster.
Open the Users tab.
Click the three dots next to the user.
Select Privileges.
Choose the required privileges. You can grant access to a specific database or grant the same privileges for all databases by enabling Identical for all databases in the top right.
Privilege |
Description |
|
Read data from tables, views, and sequences. |
|
Add new rows into tables. |
|
Modify existing rows in tables. |
|
Delete rows from tables. |
|
Quickly delete all rows in a table (without logging each row deletion). |
|
Create new objects (tables, views, functions, etc.). |
|
Use a table as a foreign key. |
|
Create and execute triggers on a table. |
|
Create temporary tables. |
|
Create new databases. |
|
Create new roles. |
You can change the user password:
PostgreSQL extensions allow you to expand the functionality of PostgreSQL databases by adding additional capabilities to solve certain tasks. You can read more about extensions in the PostgreSQL documentation.
To enable or disable extensions:
Go to the Databases section and click on the cluster.
Go to the Configuration tab.
Click Modify next to Extensions.
Select the database and the required extensions. To apply the same extensions to all databases in the cluster, enable the Use the same extensions for all databases option.
The following extensions are available:
Extension |
Description |
|
Index and table integrity checking. |
|
Case-insensitive string type. |
|
Collects and analyzes SQL query execution statistics. |
|
String search and comparison using trigrams (fuzzy search). |
|
Cryptographic functions: hashing, encryption, digital signatures. |
|
Work with geographic and geometric data (GIS). |
|
Topological models for spatial data. |
|
Generate UUIDs of various versions. |
|
Vector data type with ivfflat and hnsw indexes for similarity search. |
|
Job scheduling agent |
You can change database settings to optimize its performance.
By default, the database is created with the parameters that are suitable for most tasks and will ensure the performance of the selected configuration. However, if your project requires specific settings, you can change them as you wish.
Be careful and change parameters only if you are sure of their purpose. Incorrect configuration can negatively affect the operation of the database and its performance.
Go to the Databases section and click on the cluster.
Go to the Configuration tab.
Click Modify parameters next to Database parameters.
Adjust the parameters. To read more about each parameter, click Open description next to it.
Click Apply at the bottom of the page.
Parameter |
Values |
Default |
0–100 |
0.1 |
|
1–262143 |
3 |
|
1–2147483 |
60 |
|
0–100 |
0.2 |
|
0–100 |
0.2 |
|
-1–2147483647 |
-1 |
|
10–10000 |
200 |
|
0–1073741823 |
100 |
|
1–2147483647 |
1000 |
|
64–2147483647 |
4096 |
|
0–2147483647 |
0 |
|
1–2147483647 |
8 |
|
0–2147483647 |
0 |
|
0–262143 |
0 |
|
1–262143 |
200 |
|
16–1073741823 |
31232 |
|
-1–262143 |
2048 |
|
100–1073741823 |
1024 |
|
64–2147483647 |
436 |
|
— |
read committed |
|
1–2147483647 |
524288 |
|
2–2147483647 |
1024 |
|
2–2147483647 |
80 |
|
0–262143 |
8 |
|
0–262143 |
4 |
|
0–1024 |
2 |
|
0–1024 |
8 |
|
0–1024 |
2 |
|
On/Off |
On |
|
0–256 |
0 |
|
— |
safe_encoding |
|
0–256 |
64 |
|
1–10 |
2 |
|
On/Off |
Off |
|
On/Off |
On |
|
On/Off |
On |
|
On/Off |
On |
|
On/Off |
On |
|
On/Off |
On |
|
On/Off |
On |
|
On/Off |
On |
|
On/Off |
On |
|
On/Off |
On |
|
On/Off |
On |
|
On/Off |
On |
|
On/Off |
Off |
|
On/Off |
Off |
|
On/Off |
On |
|
On/Off |
On |
|
On/Off |
On |
|
On/Off |
Off |
|
1–2147483647 |
8 |
|
0–2147483647 |
900000 |
|
On/Off |
On |
|
— |
auto |
|
On/Off |
Off |
|
On/Off |
On |
|
0–2147483647 |
0 |
|
-13:59–+14:00 |
— |
|
On/Off |
Off |
|
1–2147483647 |
64 |
|
-1–10000 |
200 |
|
30–86400 |
300 |
|
0–1 |
0.5 |
|
On/Off |
Off |
|
0–10 |
4 |
|
0–1000 |
1 |
|
On/Off |
Off |
|
-1–2147483647 |
-1 |
|
On/Off |
Off |
|
1024–2147483647 |
33554432 |
You can easily restore the default parameters:
Go to the Databases section and click on the cluster.
Go to the Configuration tab.
Click Modify parameters next to Database parameters.
Scroll down to the bottom of the page and click Restore default settings.
Be careful: the parameters will be reset immediately, without additional confirmation.
You can connect to your databases using Adminer or via terminal. Connecting via Adminer is possible only if the cluster has a public IP address.
You can connect to the database via the built-in web interface Adminer.
Go to the Databases section and click on the cluster.
Дlick the Web Interface button and select Adminer.
Install the PostgreSQL client:
sudo apt install postgresql-client
sudo pacman -S postgresql-libs
sudo dnf install postgresql
There are two ways to connect to a PostgreSQL cluster:
You can copy the connection command from:
the Dashboard tab:
the Connection tab.
A user with the CREATE ROLE
privilege can:
CREATE USER
);CREATE ROLE
);GRANT ... TO ...
).A user is a role that is allowed to log in to the database. Such a role can connect with a username and password.
To create a user with a password, run:
CREATE USER someuser WITH PASSWORD 'password';
Here, someuser
is the username and password
is the password.
The new user will appear in the Users tab shortly after creation.
Instead of granting permissions directly to each user, it is better to create roles with the required privileges and then assign users to these roles.
Let’s create two roles: one with read-only access, and another with read and write access.
Read-only role:
CREATE ROLE app_reader;
Read/write role:
CREATE ROLE app_writer;
Assign a role to a user:
GRANT app_writer TO someuser;
By default, all PostgreSQL tables are created in the public schema. To grant permissions, create a new schema:
CREATE SCHEMA app_data;
Create tables in the new schema:
CREATE TABLE app_data.users (
id SERIAL PRIMARY KEY,
username VARCHAR(50) NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL
);
CREATE TABLE app_data.orders (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES app_data.users(id),
order_date TIMESTAMP DEFAULT now()
);
Grant access to the schema for the previously created roles:
GRANT USAGE ON SCHEMA app_data TO app_reader;
GRANT USAGE ON SCHEMA app_data TO app_writer;
Grant the right to create objects in the schema:
GRANT CREATE ON SCHEMA app_data TO app_writer;
Grant read access to all existing tables in the schema:
GRANT SELECT ON ALL TABLES IN SCHEMA app_data TO app_reader;
Grant read/write access:
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA app_data TO app_writer;
Set default permissions for new tables:
ALTER DEFAULT PRIVILEGES IN SCHEMA app_data
GRANT SELECT ON TABLES TO app_reader;
ALTER DEFAULT PRIVILEGES IN SCHEMA app_data
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO app_writer;
And default permissions for new sequences:
ALTER DEFAULT PRIVILEGES IN SCHEMA app_data
GRANT USAGE, SELECT ON SEQUENCES TO app_writer;
To create a dump, run:
pg_dump -x 'postgresql://<user>:<password>@<host>:5432/<db>' | gzip > default_db.sql.gz
The -x (--no-privileges)
flag excludes GRANT
and REVOKE
commands from the dump, since permission management is handled via the control panel.
Without this flag, errors may occur when loading the dump, though they won’t affect data restoration.
To load a dump, run:
zcat default_db.sql.gz | psql 'postgresql://<user>:<password>@<host>:5432/<db>'
This command decompresses the dump and passes it to the PostgreSQL client for execution.