PostgreSQL Storage - webbukkit/dynmap GitHub Wiki

This option one of the 4 storage options of Dynmap. It is an advanced storage layout, for example a separate service that hosts the database needs to be set-up, which will be explained in this guide.

Installation

Apologies, I would need to go over installation of the database again myself. Documentation can be found at https://www.postgresql.org/

Configuring Postgres Database

Using a terminal or command line on the server that is hosting the minecraft server, we will create a new database and add some database users.

Creating a new database in Postgres

You will notice statements like "CREATE DATABASE" after entering a command. This is normal.

C:\Program Files\PostgreSQL\15\bin>psql -U postgres
Password for user postgres:
postgres=# CREATE DATABASE <DATABASE_NAME>;
CREATE DATABASE
Postgres example (Click to expand)
C:\Program Files\PostgreSQL\15\bin>psql -U postgres
Password for user postgres:
postgres=# CREATE DATABASE dynmap;
CREATE DATABASE

Add new users

note: If the Postgres server is on the same server as the minecraft server. <minecraftserver_ip> should just be localhost

postgres=# CREATE USER <DYNMAP_USER> WITH PASSWORD '';
CREATE ROLE
postgres=# ALTER DATABASE <DYNMAP_DATABASE> OWNER TO <DYNMAP_USER>;
ALTER DATABASE
Postgres example (Click to expand)
postgres=# CREATE USER dynamp WITH PASSWORD 'CHANGE_ME_QUICK';
CREATE ROLE
postgres=# ALTER DATABASE dynmap OWNER TO dynmap;
ALTER DATABASE

If you made a mistake and need to delete the user, this is how.

postgres=# DROP USER ;
Postgres example (Click to expand)
postgres=# DROP USER dynmap;
A note: You can do this for databases, schemas (dynmap doesn't use any I believe), and users. If you play around with this, you may permanently lose data.
postgres=# DROP DATABASE dynmap;
postgres=# DROP SCHEMA maps;

After you create a new user, try logging into the user. (after you logout from the postgres user via "exit")

postgres -u 
psql (15.3)
WARNING: Console code page (437) differs from Windows code page (1252)
         8-bit characters might not work correctly. See psql reference
         page "Notes for Windows users" for details.
Type "help" for help.

postgres=#

Postgres Privileges/Permissions

Postgres has these permissions available to set to MySQL users.

  • ALL PRIVILEGES - Grant all privileges to the user
  • CREATE - Allows user to create databases/tables
  • DELETE - Allows user to delete rows(data) from a table
  • DROP - Allows user to drop databases and tables
  • INSERT - Allows user to insert rows(data) to a table
  • SELECT - Allows user to read from a database
  • UPDATE - Allows user to update data in a table

Editing dynmap/configuration.txt

The database driver for Postgres should be installed already (JDBC I believe, verify this).

The last step is to configure the dynmap configuration.txt so it connects to the database and uses it for storage. change the following part of the configuration.txt:

storage:
  # Filetree storage (standard tree of image files for maps)
  type: filetree
  # SQLite db for map storage (uses dbfile as storage location)
  #type: sqlite
  #dbfile: dynmap.db
  # MySQL DB for map storage (at 'hostname':'port' with flags "flags" in database 'database' using user 'userid' password 'password' and table prefix 'prefix')
  #type: mysql
  #hostname: localhost
  #port: 3306
  #database: dynmap
  #userid: dynmap
  #password: dynmap
  #prefix: ""
  #flags: "?allowReconnect=true&autoReconnect=true"

to:

Postgres enabled (Click to expand)
storage:
  # Filetree storage (standard tree of image files for maps)
  #type: filetree <- DONT FORGET TO COMMENT THIS OUT
  # SQLite db for map storage (uses dbfile as storage location)
  #type: sqlite
  #dbfile: dynmap.db
  # MySQL DB for map storage (at 'hostname':'port' with flags "flags" in database 'database' using user 'userid' password 'password' and table prefix 'prefix')
  type: postgres
  hostname: <postgres_ip/postgres_hostname/postgres_domain>
  port: 5432
  database: <DYNMAP_DATABASE>
  userid: <DYNMAP_USER>
  password: <DYNMAP_USER_PASSWORD>
  prefix: "" # Can add prefix for tables if you want
  flags: "?allowReconnect=true&autoReconnect=true"

example:

Postgres example (Click to expand)
storage:
  # Filetree storage (standard tree of image files for maps)
  #type: filetree <- DONT FORGET TO COMMENT THIS OUT
  # SQLite db for map storage (uses dbfile as storage location)
  #type: sqlite
  #dbfile: dynmap.db
  # MySQL DB for map storage (at 'hostname':'port' with flags "flags" in database 'database' using user 'userid' password 'password' and table prefix 'prefix')
  type: postgres
  hostname: localhost
  port: 5432
  database: dynmap
  userid: dynmap
  password: CHANGE_ME_QUICK!
  prefix: "" # Can add prefix for tables if you want
  flags: "?allowReconnect=true&autoReconnect=true"
Now save the file and start the minecraft server, check if dynmap succesfully created and connected to the Postgres database.

Post setup

All that was needed for me to get this working was to create the database. I think I had some issues with my user's privileges so those may need to be adjusted.

⚠️ **GitHub.com Fallback** ⚠️