ZeldaFan0225 / AI_Horde_Discord

A discord bot to interact with https://aihorde.net
GNU Affero General Public License v3.0
50 stars 14 forks source link

Postgres database setup #39

Closed huemobb closed 1 year ago

huemobb commented 1 year ago

Is your feature request related to a problem? Please describe. Its not easy to figureout all that postgres stuff if your a noob especially [...]

Describe the solution you'd like A step by step guide to set up a postgres database to use for this bot

Describe alternatives you've considered At least a link to another guide that would work for using this bot

Additional context Theres just no info on what a postgres database even is. Ive never heard of it until i saw it here. its got loads of different options for you to download and its so unintuitive like they list every software version in the list and make it so you can pick every single one if you wanted to but would that do anything? is doing it that way required? or should i pick the very newest version number btw ends up at the bottom of the list because its in version oldest at the top newest at the bottom of the list. and what about everything else? its trying to push like 7 different programs and drivers and shit and i try my best to get through all of that and then it just cant connect to their server and gets stuck. idk it would help idiots like me alot for a few steps how to do that thanks

ZeldaFan0225 commented 1 year ago

PostgreSQL (also referred to as Postgres) is a SQL database, the download can be found here: https://www.postgresql.org/download/

To set it up download it and start it, then set up a user and a database and grant the user privileges on said database, many guides can be found online, as an example below you can find what ChatGPT replied on how to set up PostgreSQL which i found to be pretty good:

Sure! Here's a step-by-step guide on how to install PostgreSQL and set up a basic user and database for production:

Step 1: Install PostgreSQL

  1. For Linux (Ubuntu):

    • Open a terminal and update the package list: sudo apt update
    • Install PostgreSQL: sudo apt install postgresql
  2. For macOS (using Homebrew):

    • Open Terminal and install Homebrew (if not installed): /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    • Install PostgreSQL: brew install postgresql
  3. For Windows:

Step 2: Start and Enable PostgreSQL

  1. For Linux:

    • PostgreSQL should start automatically after installation. If not, you can start it using: sudo systemctl start postgresql
    • To enable PostgreSQL to start on boot, run: sudo systemctl enable postgresql
  2. For macOS (using Homebrew):

    • To start PostgreSQL, run: brew services start postgresql
    • Homebrew services will automatically enable PostgreSQL to start on boot.
  3. For Windows:

    • PostgreSQL should be automatically started as a Windows service after installation.

Step 3: Set Up a Basic User and Database

  1. Connect to PostgreSQL as the default 'postgres' user:

    • For Linux and macOS, open a terminal and run: sudo -u postgres psql
    • For Windows, open the SQL Shell (psql) from the PostgreSQL program group.
  2. Once connected, you should see the PostgreSQL prompt: postgres=#

  3. Create a new user with a password and grant necessary privileges: Replace 'your_user' and 'your_password' with your desired username and password.

    CREATE USER your_user WITH PASSWORD 'your_password';
    ALTER USER your_user WITH SUPERUSER CREATEDB CREATEROLE;

    The above commands will create a new user, set the password, and grant superuser, createdb, and createrole privileges. For production use, you may want to adjust the user's permissions based on your application's requirements.

  4. Create a new database: Replace 'your_database' with the desired name for your database.

    CREATE DATABASE your_database OWNER your_user;

    This command will create a new database owned by the user you created in the previous step.

  5. Exit the PostgreSQL prompt: Press Ctrl + D (on Linux/macOS) or type \q and press Enter (on Windows) to exit.

Step 4: Configure PostgreSQL for Production (Optional) For a production setup, you should consider adjusting some PostgreSQL configuration settings based on your server's resources and workload. The configuration file is typically located at /etc/postgresql/<version>/main/postgresql.conf on Linux or C:\Program Files\PostgreSQL\<version>\data\postgresql.conf on Windows.

Some common settings to optimize for production are:

Remember to carefully review and test any configuration changes before applying them to a production environment.

That's it! Your PostgreSQL installation should now be ready for production use with a basic user and database set up. Remember to regularly back up your database and apply security best practices to protect your data.