Database Import Using Docker¶
Introduction¶
This section will help setup and initialize a database for the application, as well as import data into it.
Docker Image and Volume¶
The development Docker images have various PostgreSQL versions available. For this example, we have selected PostgreSQL 17 as the database. PostgreSQL 14, 15, or 16 could also be selected. There is an option which allows you to select which to include. See the usage help for more information on dbash.sh.
Make sure to create a Docker volume to hold the PostgreSQL database before starting the Docker container. You can list all available docker volumes with: docker volume ls. When you create the docker volume in this manner, any compose file that refers to this volume will need to include the external: true phrase in the volumes: section. Show volume section sample
You can also reference the actual volume name with an environment variable, and create a name for the referenced volume to be used within the compose. Show named volume
To create the docker volume, run docker volume create <volume name>. For example:
docker volume create hotel_db_postgres
Should there ever be a need to remove the database (DANGER, there is no confirmation prompt) it can be removed with docker volume rm <volume name> and then recreated with docker volume create <volume name>.
Initialize the Database Cluster¶
The commands to initialize the database must be executed from within Docker container via dbash.sh (described here). Make sure to include the appropriate --pg<14|15|16|17> option when starting the session. Also, you must to pass -v <volume name> to map the just created database volume into the container. The -w allows dbash.sh to use the fwd account within the Docker image. The command will be similar to the below:
dbash.sh -v hotel_db_postgres --pg17 -w
In the docker container, the database volume is mounted to the /opt/db location. That is where the cluster will be located. But first it needs to be created. There is a script to help standardize most of the parameters in the PG cluster, and that is /usr/local/bin/fwd_create_pg_cluster.sh. The usage is:
Usage: /usr/local/bin/fwd_create_pg_cluster.sh [options]
Creates a PostgreSQL cluster with upstream initdb, compatible with the official
postgres Docker image. Safe to run on Ubuntu (host) or in an Ubuntu-based container.
Options:
--pgdata DIR Data directory (default: /opt/db/fwdcluster)
--pgport PORT Conection port (default: 5432)
--locale LOCALE Cluster locale (default: en_US.UTF-8)
--encoding ENC Cluster encoding (default: UTF8)
--auth METHOD pg_hba auth method: scram-sha-256 | md5 | password | trust
(default: scram-sha-256)
--max-connections VALUE Maximum connections (default: 100)
--postgres-password PASS Initial password for postgres superuser
--admin-user NAME Admin role name (default: fwd_admin)
--admin-pass PASS Admin role password
--user-user NAME Standard role name (default: fwd_user)
--user-pass PASS Standard role password
--temp-port PORT Temporary port for bootstrap (default: 55432)
--socket-dir DIR Unix socket dir for bootstrap (default: /tmp)
--force Remove the cluster if it already exists.
--start Start the cluster after creating it.
Examples:
/usr/local/bin/fwd_create_pg_cluster.sh --pgdata /data/pg17 --locale en_US.UTF-8 --encoding UTF8 \
--pgport 5433 \
--max-connections 200 \
--auth scram-sha-256 \
--postgres-password adminpw \
--admin-user app_admin --admin-pass S3cret! \
--user-user app_user --user-pass userpw
Notes:
- Uses initdb (NOT pg_createcluster), so the layout matches postgres Docker images.
- Ensures correct ownership and permissions on PGDATA.
By default it will setup fwd_admin / fwd_user with admin/user. Pass the appropriate options to modify them.
This is basic usage for Hotel GUI from inside a Docker container:
sudo fwd_create_pg_cluster.sh --pgdata /opt/db/fwdcluster
If there is already a cluster in place, it will warn you, and exit. You would need to include the --force option to replace an existing cluster.
If you would like to pass the command directly in via dbash.sh from the host, it would be similar to:
dbash.sh -v hotel_db_postgres --pg17 -w --pgdata=fwdcluster -c "sudo fwd_create_pg_cluster.sh --pgdata /opt/db/fwdcluster"
Note the addition of the --pgdata=<cluster> option. This will create a container that will startup the database cluster if it has already been created, as well as setting the PGDATA environment variable, which is used by some of the PG control scripts like startup_pg.sh and shutdown_pg.sh.
Database Control and Import¶
Once the directory is setup and the database is initialized, we can import data. The dump files (.d) are an integral part of the import, and should be placed in the data/dump/ directory corresponding to the directory for the database that is to be imported. So if there is a hotel database, for example, the .d files for that database would be placed in data/dump/hotel/ directory.
Hotel GUI includes a tool that allows demo data to be generated after conversion is completed. If you are interested in making the data look more realistic, click here to show how to run the tool
Start PostgreSQL and Import Data¶
If you started dbash.sh with the --pgdata=<cluster> option, you should have seen the startup of the database occur. Output should look like
If you did not start the database when you launched dbash.sh, you can get similar results by running this inside the PG Docker container:
(cd /tmp; PGDATA=/opt/db/fwdcluster sudo startup_pg.sh &)
The PGDATA=/opt/db/fwdcluster is not needed if that environment variable is already set. NOTE: The & does launch the process in the background, but the prompt is not returned. Press "enter" so that you can see your prompt returned to you for the next command.
At this point the database is ready to take data via import of a dump with deploy/server/importdbs.sh. The deploy/server/importdbs.sh script utilizes a configured directory to determine the JDBC connected databases, then makes those database connections and performs imports with the dump data found in the specified directory. The directory will be on your host and mapped into the container. The schema data should be in the application jar file, as built during the conversion. If you have not yet configured the runtime, the Runtime Setup Using Docker will help.
(cd deploy/server; ./importdbs.sh -r ../../data/dump/ -a ../lib/hotel.jar)
This script then feeds those values to the
./p2j/tools/scripts/import.sh tool for import.
Shutdown the Database¶
You can perform a clean shutdown the PostgreSQL database with the command:
sudo shutdown_pg.sh
Version to Version Migration¶
If you need to migrate an existing PostgreSQL database from an earlier major version (e.g. 14, 15, 16) to PostgreSQL 17, see PostgreSQL Migration.
© 2004-2026 Golden Code Development Corporation. ALL RIGHTS RESERVED.