Default Username/Password for PostgreSQL Server in Rails 4

Bilal Shahid Apr 03, 2022
  1. Initial Configuration and Setup of PostgreSQL
  2. Create Different USERS in PostgreSQL
  3. View USERS and ALTER Forgotten Passwords in PostgreSQL
Default Username/Password for PostgreSQL Server in Rails 4

Many PostgreSQL users ask about the USERNAME and PASSWORD for their database for the first time when logging in perhaps. However, just learning these settings isn’t all you need to know.

What is Server in Rails 4? It uses the PostgreSQL server with Ruby on Rails 4.

Thus integrating the back-end with a front-end application that uses the ROR framework, short for Ruby on Rails.

Today we will be looking in-depth at the basic setup of your PostgreSQL and the default user configurations that precede it.

Initial Configuration and Setup of PostgreSQL

You’ll be hit with something like this the first time you run the PostgreSQL setup.

postgres user config

It asks you to provide a password for the SUPERUSER called POSTGRES. So when you open PGADMIN4 or the console version PSQL, you’ll now want to log in using the username as POSTGRES and the password as typed above.

How to log in using PGADMIN4?

  1. Boot up PGADMIN4.

  2. On the startup screen, you’ll be hit up with this.

    postgres user login

  3. Here, you will enter the password you used in the setup to log in.

    If you forgot the password, you can go right ahead and click on RESET MASTER PASSWORD and follow the on-screen instructions.

Now we will learn how to log in using PSQL.

  1. Open CMD and run it with user privileges.

  2. In CMD, enter:

    C:\Users\User_Name > cd C:\Program Files\PostgreSQL\14\bin
    

    Or as specified by your system. Instead of 14, there may be a different version and a different directory to open the bin folder.

  3. Now that you are inside the directory, type psql.exe.

    C:\Program Files\PostgreSQL\14\bin> psql -U postgres
    

    The statement above tends to open the psql with the username as postgres, which is our default superuser.

  4. This will lead you to:

Password for user postgres:

Here you will enter the same password you set in the setup to log in and click Enter. You are now logged in.

the Superuser POSTGRES in PostgreSQL

POSTGRES is the initial SUPERUSER of our database. It has all the known privileges to access and view an entire collection of database objects, views, and whatnot.

You can issue your SUPERUSERS or just USERS with limited access. A SUPERUSER is the only entity that can issue CREATE commands to add new users to the system.

Create Different USERS in PostgreSQL

You can use the following statement to make a new SUPERUSER with a unique name.

Create ROLE Wild_Cat WITH SUPERUSER

Or if you want to log in.

Create ROLE Wild_Cat Login

And then log in using psql.

View USERS and ALTER Forgotten Passwords in PostgreSQL

If you have different USERS, you can view them as follows.

select * from pg_user;

And then, from the list provided, such as in our example, we had the user WILD_CAT, use the ALTER statement to RESET the password.

pg user table

From here, we can then call the ALTER statement as:

ALTER USER wild_cat WITH PASSWORD '[your_password]'

So today, we learned about the various ways we can define and use USERS in PostgreSQL in SERVER IN RAILS 4. We hope you continue learning and following our tutorials to better understand the concepts behind different solutions to a problem.

Author: Bilal Shahid
Bilal Shahid avatar Bilal Shahid avatar

Hello, I am Bilal, a research enthusiast who tends to break and make code from scratch. I dwell deep into the latest issues faced by the developer community and provide answers and different solutions. Apart from that, I am just another normal developer with a laptop, a mug of coffee, some biscuits and a thick spectacle!

GitHub