London Escorts sunderland escorts 1v1.lol unblocked yohoho 76 https://www.symbaloo.com/mix/yohoho?lang=EN yohoho https://www.symbaloo.com/mix/agariounblockedpvp https://yohoho-io.app/ https://www.symbaloo.com/mix/agariounblockedschool1?lang=EN
-1.2 C
New York
Sunday, February 2, 2025

Learn how to arrange pgSQL for Fluent 4?


If you’re already accustomed to PostgreSQL, however you do not know a lot about how one can use databases in Vapor, it is best to learn my different tutorial about Fluent for freshmen.

A fast intro to PostgreSQL

PostgreSQL is an open supply database, it is obtainable for macOS, Linux and another working techniques. You possibly can set up it through the use of the de-facto package deal supervisor on each platform. 📦

# Linux
sudo apt-get set up postgresql postgresql-contrib
sudo service postgresql begin
# test service standing
sudo service --status-all
sudo service postgresql standing

# macOS
brew set up postgresql
brew companies begin postgresql
# test service standing
brew companies checklist

You will additionally must set a correct password for the postgres consumer, which is the admin consumer by default with godlike permissions. You possibly can change the foundation password, you simply need to log in as a root & alter the postgres consumer report with the brand new go. 🔑

# Linux
sudo -u postgres psql postgres
# macOS
psql -U postgres

# psql (12.1)
# Kind "assist" for assist.
#
# postgres=#

# ALTER ROLE
alter consumer postgres with password 'mypassword';

# exit
q

To any extent further you can entry pgSQL as root on each platforms like this:

psql -h localhost -U postgres

It is suggested to make use of a devoted consumer for each single database that you just create as an alternative of working with a shared root consumer. Let me present you how one can create a brand new DB with an related consumer.

# Listing of databases
l
# Present present database
choose current_database();
# Create new database
create database mydb;
# Change database
c mydb
# Create consumer
create consumer myuser with encrypted password 'mypassword';
# Grant privileges for consumer on the database
grant all privileges on database mydb to myuser;
# Give up from psql console
q

That is it, you may handle your database through the use of the newly created myuser account.

# Log in again to psql console with myuser utilizing mydb
psql -h localhost -U myuser mydb
# Listing all tables
dt
# Describe desk construction (can be helpful afterward)
d+ <desk>

You possibly can study extra about SQL instructions utilizing this pgSQL tutorial website.

The command beneath can utterly wipe your database, be extraordinarily cautious!

Now you might be able to mess around with Fluent, however earlier than we begin I might like to indicate you some extra suggestions & tips. Throughout growth, issues can go flawed and also you may want a recent begin on your DB. This is how one can drop & reinitiate all the things. 😱

# Reset database
c mydb
drop schema public cascade;
create schema public;
grant all on schema public to postgres;
grant all on schema public to myuser;
grant all on schema public to public;

The snippet above will delete the public schema, subsequent it will recreate it and add all the required permissions for the required customers. It is fairly simple however nonetheless harmful. ⚠️

NOTE : You possibly can execute SQL scripts straight from the terminal through the use of the next command: psql -h localhost -U myuser mydb -c "choose * from mytable;"

You possibly can wipe all the things from the command line utilizing this “one-liner”:

# Run psql command from the command line
psql -h localhost -U postgres mydb
    -c "drop schema public cascade; 
    create schema public; 
    grant all on schema public to postgres; 
    grant all on schema public to myuser; 
    grant all on schema public to public;"

I favor to have each day backups from all my databases, this little shell script can do the job.

#!/bin/bash

# Backup database
BACKUP_DIR=/Customers/tib/backups
FILE_SUFFIX=_pg_backup.sql
OUTPUT_FILE=${BACKUP_DIR}/`date +"%Y_percentm_percentd__percentH_percentM"`${FILE_SUFFIX}
PGPASSWORD="mypass" pg_dump -U myuser -h localhost mydb -F p -f ${OUTPUT_FILE}
gzip $OUTPUT_FILE

# Take away outdated backups
DAYS_TO_KEEP=30
discover $BACKUP_DIR -maxdepth 1 -mtime +$DAYS_TO_KEEP -name "*${FILE_SUFFIX}.gz" -exec rm -rf '{}' ';'

You possibly can simply restore a database from a backup by coming into the next strains to the terminal:

# Restore database
gunzip -k file.gz
psql -U myuser -d mydb -1 -f mybackup.sql

Generally after I restarted my mac it occurred to me that the PostgreSQL stopped working. I needed to run the snippet beneath to repair the difficulty. The primary line stops the service, the second initialize a brand new database, and the third will begin the service once more. Alternatively, you can begin the database once more with the brew companies begin postgresql command.

pg_ctl -D /usr/native/var/postgres cease -s -m quick
initdb /usr/native/var/postgres
pg_ctl -D /usr/native/var/postgres -l /usr/native/var/postgres/server.log begin

I am not a DevOps guru, be at liberty to tweet me if you realize why this occurred to me. 😅

Related Articles

Social Media Auto Publish Powered By : XYZScripts.com