Close Menu
  • Home
  • AI
  • Big Data
  • Cloud Computing
  • iOS Development
  • IoT
  • IT/ Cybersecurity
  • Tech
    • Nanotechnology
    • Green Technology
    • Apple
    • Software Development
    • Software Engineering

Subscribe to Updates

Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

    What's Hot

    Iran war: US responsible for strike on Iranian school, investigation finds

    March 12, 2026

    MaxLiveProtect: eBPF-Powered Network Infrastructure Security

    March 12, 2026

    SBS Bank begins shift to cloud-native core banking platform

    March 12, 2026
    Facebook X (Twitter) Instagram
    Facebook X (Twitter) Instagram
    Big Tee Tech Hub
    • Home
    • AI
    • Big Data
    • Cloud Computing
    • iOS Development
    • IoT
    • IT/ Cybersecurity
    • Tech
      • Nanotechnology
      • Green Technology
      • Apple
      • Software Development
      • Software Engineering
    Big Tee Tech Hub
    Home»iOS Development»How to set up pgSQL for Fluent 4?
    iOS Development

    How to set up pgSQL for Fluent 4?

    big tee tech hubBy big tee tech hubApril 24, 2025045 Mins Read
    Share Facebook Twitter Pinterest Copy Link LinkedIn Tumblr Email Telegram WhatsApp
    Follow Us
    Google News Flipboard
    How to set up pgSQL for Fluent 4?
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link


    2/25/20 4:20 PM
    · 2 min read


    This is a tutorial for beginners about using PostgreSQL. I’ll show you how to automatically backup and restore the database.

    If you are already familiar with PostgreSQL, but you don’t know much about how to use databases in Vapor, you should read my other tutorial about Fluent for beginners.

    A quick intro to PostgreSQL

    PostgreSQL is an open source database, it’s available for macOS, Linux and some other operating systems. You can install it by using the de-facto package manager on every platform. 📦

    # Linux
    sudo apt-get install postgresql postgresql-contrib
    sudo service postgresql start
    # check service status
    sudo service --status-all
    sudo service postgresql status
    
    # macOS
    brew install postgresql
    brew services start postgresql
    # check service status
    brew services list
    

    You’ll also need to set a proper password for the postgres user, which is the admin user by default with godlike permissions. You can change the root password, you just have to log in as a root & alter the postgres user record with the new pass. 🔑

    # Linux
    sudo -u postgres psql postgres
    # macOS
    psql -U postgres
    
    # psql (12.1)
    # Type "help" for help.
    #
    # postgres=#
    
    # ALTER ROLE
    alter user postgres with password 'mypassword';
    
    # exit
    \q
    

    From now on you’ll be able to access pgSQL as root on both platforms like this:

    psql -h localhost -U postgres
    

    It is recommended to use a dedicated user for every single database that you create instead of working with a shared root user. Let me show you how to create a new DB with an associated user.

    # List of databases
    \l
    # Show current database
    select current_database();
    # Create new database
    create database mydb;
    # Change database
    \c mydb
    # Create user
    create user myuser with encrypted password 'mypassword';
    # Grant privileges for user on the database
    grant all privileges on database mydb to myuser;
    # Quit from psql console
    \q
    

    That’s it, you can manage your database by using the newly created myuser account.

    # Log in back to psql console with myuser using mydb
    psql -h localhost -U myuser mydb
    # List all tables
    \dt
    # Describe table structure (will be useful later on)
    \d+ 

    You can learn more about SQL commands using this pgSQL tutorial site.

    The command below can completely wipe your database, be extremely careful!

    Now you are ready to play around with Fluent, but before we start I’d like to show you some more tips & tricks. During development, things can go wrong and you might need a fresh start for your DB. Here’s how to drop & reinitiate everything. 😱

    # 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, next it’ll recreate it and add all the necessary permissions for the required users. It’s pretty straightforward but still dangerous. ⚠️

    NOTE : You can execute SQL scripts straight from the terminal by using the following command: psql -h localhost -U myuser mydb -c "select * from mytable;"

    You can wipe everything from the command line using 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 prefer to have daily backups from all my databases, this little shell script can do the job.

    #!/bin/bash
    
    # Backup database
    BACKUP_DIR=/Users/tib/backups
    FILE_SUFFIX=_pg_backup.sql
    OUTPUT_FILE=${BACKUP_DIR}/`date +"%Y_%m_%d__%H_%M"`${FILE_SUFFIX}
    PGPASSWORD="mypass" pg_dump -U myuser -h localhost mydb -F p -f ${OUTPUT_FILE}
    gzip $OUTPUT_FILE
    
    # Remove old backups
    DAYS_TO_KEEP=30
    find $BACKUP_DIR -maxdepth 1 -mtime +$DAYS_TO_KEEP -name "*${FILE_SUFFIX}.gz" -exec rm -rf '{}' ';'
    

    You can easily restore a database from a backup by entering the following lines to the terminal:

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

    Sometimes after I restarted my mac it happened to me that the PostgreSQL stopped working. I had to run the snippet below to fix the issue. The first line stops the service, the second initialize a new database, and the third will start the service again. Alternatively, you can start the database again with the brew services start postgresql command.

    pg_ctl -D /usr/local/var/postgres stop -s -m fast
    initdb /usr/local/var/postgres
    pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
    

    I’m not a DevOps guru, feel free to tweet me if you know why this happened to me. 😅


    How to set up pgSQL for Fluent 4?

    Share this article

    Thank you. 🙏

    Related posts

    How to set up pgSQL for Fluent 4?

    10/8/19 4:20 PM
    · 4 min read


    Get started with server-side Swift using the Vapor 4 framework. Learn how to build a really simple HTTP/2 backend server.

    How to set up pgSQL for Fluent 4?

    8/26/19 4:20 PM
    · 4 min read


    Vapor is the most popular server side Swift web application framework. This time we'll cover what's new in Vapor 4.

    How to set up pgSQL for Fluent 4?

    7/15/20 4:20 PM
    · 5 min read


    As a beginner server side Swift developer you'll face many obstackles. I'll show you how to avoid the most common ones.

    How to set up pgSQL for Fluent 4?

    4/1/20 4:20 PM
    · 10 min read


    Learn how to build a controller component that can serve models as JSON objects through a RESTful API written in Swift.


    Practical Server Side Swift cover image

    Get the Practical Server Side Swift book

    Swift on the server is an amazing new opportunity to build fast, safe and scalable backend apps. Write your very first web-based application by using your favorite programming language. Learn how to build a modular blog engine using the latest version of the Vapor 4 framework. This book will help you to design and create modern APIs that'll allow you to share code between the server side and iOS. Start becoming a full-stack Swift developer.

    Available on Gumroad

    On this page



    Source link

    Fluent pgSQL set
    Follow on Google News Follow on Flipboard
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Copy Link
    tonirufai
    big tee tech hub
    • Website

    Related Posts

    ios – SwiftUI iOS26+ Transition or Animation after TextField value entered

    March 12, 2026

    uikit – Why the title doesn’t follow the navigation inline state in iOS 26

    March 11, 2026

    ios – OS emoji keyboard causes UI freeze in chat TextField Flutter

    March 10, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Editors Picks

    Iran war: US responsible for strike on Iranian school, investigation finds

    March 12, 2026

    MaxLiveProtect: eBPF-Powered Network Infrastructure Security

    March 12, 2026

    SBS Bank begins shift to cloud-native core banking platform

    March 12, 2026

    Friday Night Baseball Returns to Apple TV on March 27 for 2026 MLB Season

    March 12, 2026
    About Us
    About Us

    Welcome To big tee tech hub. Big tee tech hub is a Professional seo tools Platform. Here we will provide you only interesting content, which you will like very much. We’re dedicated to providing you the best of seo tools, with a focus on dependability and tools. We’re working to turn our passion for seo tools into a booming online website. We hope you enjoy our seo tools as much as we enjoy offering them to you.

    Don't Miss!

    Iran war: US responsible for strike on Iranian school, investigation finds

    March 12, 2026

    MaxLiveProtect: eBPF-Powered Network Infrastructure Security

    March 12, 2026

    Subscribe to Updates

    Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

      • About Us
      • Contact Us
      • Disclaimer
      • Privacy Policy
      • Terms and Conditions
      © 2026 bigteetechhub.All Right Reserved

      Type above and press Enter to search. Press Esc to cancel.