Created PostgreSQL Storage (markdown)

aurorapar 2024-03-28 02:39:58 -05:00
parent c897ae6862
commit f3c92b4805
1 changed files with 130 additions and 0 deletions

130
PostgreSQL-Storage.md Normal file

@ -0,0 +1,130 @@
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
### Add new users
**note:**
If the Postgres server is on the same server as the minecraft server. <minecraftserver_ip> should just be localhost
<pre><code>postgres=# CREATE USER <DYNMAP_USER> WITH PASSWORD '<DYNMAP_USER_PASSWORD>';
CREATE ROLE
postgres=# ALTER DATABASE dynmap OWNER TO dynmap;
ALTER DATABASE</code></pre>
If you made a mistake and need to delete the user, this is how.
<pre><code>postgres=# DROP USER <DYNMAP_USER>;</pre></code>
After you create a new user, try logging into the user. (after you logout from the postgres user via "exit")
<pre><code>postgres -u <DYNMAP_USER>
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=#</code></pre>
### 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:
```yaml
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:
<details>
<summary>Postgres enabled (Click to expand)</summary>
```yaml
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"
```
</details>
example:
<details>
<summary>MySQL example (Click to expand)</summary>
```yaml
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"
```
</details>
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.