Line 327:
Line 327:
}
}
</syntaxhighlight><br />
</syntaxhighlight><br />
−
==Allow PostgreSQL to be accessed from an external application==
+
==PostgreSQL tips and trick==
+
+
===Allow PostgreSQL to be accessed from an external application===
''Useful to be able to access the database from a graphical client (like pgAdmin 4, TablePlus or Postico for example).''
''Useful to be able to access the database from a graphical client (like pgAdmin 4, TablePlus or Postico for example).''
Line 339:
Line 341:
sudo -u postgres psql discourse
sudo -u postgres psql discourse
CREATE USER my_username WITH PASSWORD 'my_password';
CREATE USER my_username WITH PASSWORD 'my_password';
−
GRANT ALL PRIVILEGES ON DATABASE "discourse" to my_username;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO my_username;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO my_username;
+
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO my_username;
+
GRANT ALL PRIVILEGES ON DATABASE discourse to my_username;
\q
\q
+
+
Refer to [https://tableplus.io/blog/2018/04/postgresql-how-to-grant-access-to-users.html PostgreSQL - How to grant access to users?] for more info.
+
+
===Dumping database===
+
+
====Use <code>pg_dump</code> to dump the database====
+
+
pg_dump -h 127.0.0.1 -d discourse -U my_username -W > discourse-backup-20190801.sql
+
+
====Use discourse internal backup tool====
+
+
It is also possible to use Discourse internal backup tool to grab a backup of the Discourse instance.
+
+
Just go to <code>Admin → Backup</code>