Deploy PostgreSQL database (Windows)
Deploy Creatio on PostgreSQL to enable database hosting on Windows-based infrastructure. Learn more about AWS RDS PostgreSQL deployment: Deploy PostgreSQL database (AWS RDS).
The general database deployment procedure for PostgreSQL on Windows is as follows:
- Install PostgreSQL. Read more >>>
- Create PostgreSQL users. Read more >>>
- Create and restore the database. Read more >>>
- Configure max connections (optional). Read more >>>
- Change database ownership (optional). Read more >>>
Use one of the following tools to deploy Creatio:
- Remote DBMS (recommended)
- Local PostgreSQL server
1. Install PostgreSQL
If a PostgreSQL server is already set up, skip to step 2. Read more >>>
Before deploying PostgreSQL database, make sure you have PostgreSQL 16 or later installed. Otherwise, download PostgreSQL setup files (official PostgreSQL documentation).
If you want to set up PostgreSQL clustering, follow the official vendor documentation. Learn more: High Availability, Load Balancing, and Replication Table (official PostgreSQL documentation).
2. Create PostgreSQL users
If a superuser and a regular user are already set up, skip to step 3. Read more >>>
Create the following database users for PostgreSQL deployment:
- A superuser who has maximum access privileges on the database server level. This user restores the Creatio database from a backup file and assigns access permissions.
- A regular user who has limited permissions. This user becomes the owner of the restored database and is used in Creatio database connection strings during runtime.
Switch to the postgres system user and run the PostgreSQL interactive terminal:
-
Open the command-line interface.
-
Navigate to the PostgreSQL software installation directory:
cd /D "path_to_PostgreSQL_directory"path_to_PostgreSQL_directoryis the PostgreSQL installation directory. -
Navigate to the directory with executables:
cd bin -
Set the
postgresuser password in the environment variable:set PGPASSWORD=postgres_passwordpostgres_passwordis thepostgresuser password. -
Run the PostgreSQL interactive terminal as
postgres:psql.exe --username postgres
1. Set up superuser
The examples below use creatio_superuser and creatio_superuser_password. Replace them with custom values everywhere they appear in the subsequent SQL script.
To create a superuser who has maximum access privileges:
-
Create the superuser:
CREATE USER creatio_superuser; -
Grant superuser privileges:
ALTER ROLE creatio_superuser WITH SUPERUSER; -
Allow the superuser to log in:
ALTER ROLE creatio_superuser WITH LOGIN; -
Set the superuser password:
ALTER ROLE creatio_superuser WITH PASSWORD 'creatio_superuser_password';
2. Set up regular user
The examples below use creatio_user and creatio_user_password. Replace them with custom values in the subsequent SQL script and in the "ConnectionStrings.config" file in the root Creatio directory.
To create a regular user who has limited permissions:
-
Create the regular user:
CREATE USER creatio_user; -
Allow the regular user to log in:
ALTER ROLE creatio_user WITH LOGIN; -
Set the regular user password:
ALTER ROLE creatio_user WITH PASSWORD 'creatio_user_password'; -
Exit the PostgreSQL environment:
\q
3. Create and restore the database
To restore a PostgreSQL database from a backup file, the psql.exe and pg_restore.exe utilities are required. Both are part of the Command Line Tools PostgreSQL component that comes with the PostgreSQL Server and are located in the PostgreSQL software installation directory.
Install PostgreSQL components:
- Download a PostgreSQL interactive installer on the official vendor website.
- Select the Command Line Tools component during installation. Selecting the other components is optional.
1. Create database
The example below uses "creatio_superuser_password." Replace it with a custom value.
-
Open Command Prompt.
-
Navigate to the PostgreSQL software installation directory:
cd /D "path_to_PostgreSQL_directory" -
Navigate to the directory with executables:
cd bin -
Set the superuser password in the environment variable:
set PGPASSWORD=creatio_superuser_password -
Connect to the PostgreSQL server and create a database that has an arbitrary name and the owner set to the
creatio_user:psql.exe --host=pg_server_host --port=pg_server_port --username=creatio_superuser --dbname=pg_admin_db -c "CREATE DATABASE creatiodb WITH OWNER = creatio_user ENCODING = 'UTF8' CONNECTION LIMIT = -1"Where:
pg_server_hostis the PostgreSQL server host.pg_server_portis the PostgreSQL server port.creatio_superuseris the superuser for connecting to the PostgreSQL server.pg_admin_dbis the name of the PostgreSQL database to connect to for executing the command. If no databases exist yet or if an attempt to connect triggers the 'FATAL: database "pg_admin_db" does not exist' error, use the default databasetemplate1.creatiodbis the name of the PostgreSQL database that hosts Creatio tables.creatio_useris the regular user who is granted permission to use and update the Creatio database.
2. Restore the database
Restore the database from the "*.backup" file with the --no-owner and --no-privileges parameters:
pg_restore --host=pg_server_host --port=pg_server_port --username=creatio_superuser --dbname=creatiodb --no-owner --no-privileges --verbose path_to_db.backup
Where:
pg_server_hostis the PostgreSQL server host.pg_server_portis the PostgreSQL server port.creatio_superuseris the superuser for connecting to the PostgreSQL server.creatiodbis the name of the PostgreSQL database to restore to. Use the name specified in theCREATE DATABASEcommand.path_to_db.backupis the path to the database backup file. The backup file is supplied together with Creatio installation files and is located in thedbdirectory of the root Creatio directory.
3. Create type casts
Create type casts via one of the following ways:
Download and execute the CreateTypeCastsPostgreSql.sql SQL script:
Download: CreateTypeCastsPostgreSql.sql.
psql.exe --host=pg_server_host --port=pg_server_port --username=creatio_superuser --dbname=creatiodb --file=path_to_CreateTypeCastsPostgreSql.sql
Where:
pg_server_hostis the PostgreSQL server host.pg_server_portis the PostgreSQL server port.creatio_superuseris the superuser for connecting to the PostgreSQL server.creatiodbis the name of the PostgreSQL database to restore to.path_to_CreateTypeCastsPostgreSql.sqlis the path to the "CreateTypeCastsPostgreSql.sql" file.
Run the following SQL script as a single batch or individually:
DROP CAST IF EXISTS (varchar AS integer);
CREATE CAST (varchar AS integer)
WITH
INOUT AS IMPLICIT;
DROP CAST IF EXISTS (varchar AS uuid);
CREATE CAST (varchar AS uuid)
WITH
INOUT AS IMPLICIT;
DROP CAST IF EXISTS (text AS integer);
CREATE CAST (text AS integer)
WITH
INOUT AS IMPLICIT;
DROP CAST IF EXISTS (uuid AS text);
CREATE CAST (uuid AS text)
WITH
INOUT AS IMPLICIT;
DROP CAST IF EXISTS (text AS boolean);
CREATE CAST (text AS boolean)
WITH
INOUT AS IMPLICIT;
DROP CAST IF EXISTS (text AS numeric);
CREATE CAST (text AS numeric)
WITH
INOUT AS IMPLICIT;
DROP CAST IF EXISTS (text AS uuid);
CREATE CAST (text AS uuid)
WITH
INOUT AS IMPLICIT;
DROP FUNCTION IF EXISTS public."fn_CastTimeToDateTime" CASCADE;
CREATE FUNCTION public."fn_CastTimeToDateTime"(
sourceValue TIME WITHOUT TIME ZONE
)
RETURNS TIMESTAMP WITHOUT TIME ZONE
AS $BODY$
BEGIN
RETURN (MAKE_DATE(1900, 01, 01) + sourceValue)::TIMESTAMP WITHOUT TIME ZONE;
END;
$BODY$
LANGUAGE PLPGSQL;
DROP CAST IF EXISTS (TIME WITHOUT TIME ZONE AS TIMESTAMP WITHOUT TIME ZONE);
CREATE CAST (TIME WITHOUT TIME ZONE AS TIMESTAMP WITHOUT TIME ZONE)
WITH
FUNCTION public."fn_CastTimeToDateTime"(
TIME WITHOUT TIME ZONE
) AS IMPLICIT;
When the SQL script runs, PostgreSQL may display warnings for casts that already exist. These warnings are expected and can be ignored.
As a result, the PostgreSQL database will be restored and ready for Creatio deployment.
4. Configure max connections (optional)
Take these steps only if your Creatio deployment is going to serve more than 100 simultaneous users.
-
Calculate
max_connectionsparameter value based on the expected number of simultaneous users:Expected number of users * 1.5If the result is less than 1024, use the resulting number. If the result is 1024 or greater, set the parameter to 1024.
-
Calculate
shared_buffersparameter value based on themax_connectionsvalue:max_connections * 0.24MBSet the parameter value in MB and round the resulting value up. For example, if
max_connectionsis 1024,shared_buffersis 245.76MB, rounded up to 246MB.
Set the calculated values in the following parameters of the "postgresql.conf" file:
max_connectionsshared_buffers
To locate the "postgresql.conf" file, run the following command in the PostgreSQL interactive terminal:
SHOW config_file;
5. Change database ownership (optional)
By default, the user who runs the pg_restore command (typically "postgres") remains the owner of the database and its objects. If a regular user should own the database instead of the superuser, follow the steps below.
To change the database ownership:
-
Change the database owner to the regular user:
psql.exe --host=pg_server_host --port=pg_server_port --username=creatio_superuser --dbname=pg_admin_db --command "ALTER DATABASE creatiodb OWNER TO creatio_user"Where:
pg_server_hostis the PostgreSQL server host.pg_server_portis the PostgreSQL server port.creatio_superuseris the superuser for connecting to the PostgreSQL server. This user must be an administrator (superuser) or have theALTER DATABASEprivileges.pg_admin_dbis the name of the PostgreSQL database to connect to for executing the command. If no databases exist yet or if an attempt to connect triggers the 'FATAL: database "pg_admin_db" does not exist' error, use the default databasetemplate1.creatio_useris the new database owner. This user is used to set up a connection to the Creatio database.creatiodbis the name of the database whose owner is being changed.
-
Download and run the SQL script to transfer ownership of all database objects to the regular user:
To change the database ownership, use the database ownership transfer SQL script.
- For Postgres version 11 and later: Download the script.
- For Postgres version 10 and earlier: Download the script.
psql.exe --host=pg_server_host --port=pg_server_port --username=creatio_superuser --dbname=creatiodb --file=path_to_database_ownership_transfer_script.sql --variable owner=creatio_user --variable ON_ERROR_STOP=1Where:
pg_server_hostis the PostgreSQL server host.pg_server_portis the PostgreSQL server port.creatio_superuseris the superuser for connecting to the PostgreSQL server. This user must be an administrator (superuser) or the Creatio database owner.creatio_useris the new database owner. This user is used to set up a connection to the Creatio database.creatiodbis the name of the database whose owner is being changed.path_to_database_ownership_transfer_script.sqlis the path to the previously saved database ownership transfer script.
See also
General setup procedure for data caching server (Redis)
Set up Creatio application server on IIS