I installed PosgreSQL 10.5 on a Mac running macOS 10.13.6 using Homebrew by following this tutorial. After installation, I ran =# \du to view all users. I saw the user with my Mac's name that the tutorial says PostgreSQL creates during installation, but the "postgres" default user was not created (or at least did not appear).
My Main Issue is...
I need to login to PostgreSQL 'at the root', and I either do not understand exactly what that means, or something is wrong. In following the very first steps from the PostgreSQL wiki's First Steps documentation, it says to...
First connect/login as root:
# su - postgres
$ psql
psql (9.6.0)
Type "help" for help.
But when I open a terminal window and type in su - postgres
it asks for a password. I've typed in every password I could possibly have given that role, and it just says su: Sorry
.
I did some research and tried to change the password by doing this:
postgres=# \password postgres
.
That prompted me to enter a password twice, and it seemed to work. But, when I go back and run: su - postgres
, it just gives me the same su: sorry
.
So I tried typing in: psql postgres
. This at least changed the $ to postgres=#, which tells me that I am at the PostgreSQL command line, and then the same: su: postgres
, but that just changed the (=) sign to a (-), so now it changed to: postgres-#
I thought that maybe this meant that I was "logged into PostgreSQL at the root, but then I ran the following:
postgres=# su - postgres
postgres-# CREATE SCHEMA test
postgres-# CREATE USER tester PASSWORD 'P@ssword1'
postgres-# GRANT ALL ON SCHEMA test TO tester
postgres-# \q
...and none of that worked. It did not create a user or a schema.
History...
- I've installed/uninstalled PostgreSQL on this Mac several times in the past for testing
- I've also installed/uninstalled pdAdmin for various reasons
It is highly possible that I did something in all of that shuffle that brought about this issue with the 'postgres' role not being created during this Homebrew instal. So, I did read through the rest of that tutorial and I did type in $ createuser postgres
and that did seem to create the 'postgres' role. I tried to use ALTER ROLE
to give that role Create DB
but I never could get it to work using the command line, so I just opened pgAdmin, saw the role, granted it Create DB, and then back in command line ran =# \du
again, and Create DB
did appear next to the 'postgres' role I'd created. I added everything in pgAdmin, and now it looks like this.
List of roles
Role name | Attributes | Member of
----------------+------------------------------------------------------------+-----------
MyMacsNameHere | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
postgres | Superuser, Create role, Create DB, Replication | {}
My end goal...
I am trying to follow along with this YouTube tutorial about creating a Flask web application from scratch. In the YouTube tutorial, he uses MySQL, but I want to use PostgreSQL. Needless to say, I am up against a learning curve.