Databases on HostingSwift
Create managed PostgreSQL or MySQL, connect safely, and understand what to back up.
Most applications need a database. Here is how to create and connect one properly.
Create one
From the panel, create a PostgreSQL or MySQL database. You receive:
A hostname (a private address on our mesh — not public).
A database name, username, and password.
A port (5432 for PostgreSQL, 3306 for MySQL).
The database is reachable over the private network by default, which means it is not exposed to the internet at all. That is deliberate — see Private mesh networking.
Connect
# PostgreSQL
psql "postgresql://user:[email protected]:5432/dbname"
# MySQL
mysql -h db.internal.example -u user -p dbnameFrom an application, use the connection string in an environment variable — never commit it to source control.
Golden rules
Never use the superuser for an application. Create a role with rights only on your database.
Keep it on the private network. If you must connect from outside, do it over the VPN, not by opening the port.
Use strong, unique passwords stored in secrets, not code.
Know what you are backing up. Files without the database is a theme with no content; the database without files is content with no images. Back up both — see Database backups.
Version your schema. Use migrations so you can recreate the schema anywhere.
Connecting from your app on a VPS
Your VPS is on the same mesh, so it reaches the database at the private hostname with no extra configuration. If your firewall is strict, ensure the mesh interface is allowed — see Firewall basics.
Choosing PostgreSQL or MySQL
PostgreSQL — richer features (JSONB, extensions, strong standards compliance). The default recommendation for new projects.
MySQL/MariaDB — enormous ecosystem, extremely well documented, common with PHP apps.
Both are excellent. Pick based on your software's documentation and move on.
Related reading