How to Run PostgreSQL as portable executable without installing in Windows

This is probably just another notes that I wrote, because I don’t think everyone will need this, but if anyone need this, I think this will be helpful.

So, long story short, I don’t want to install another database service in my Windows Dev Box (on my ASUS A43SV), like I did with MySQL 8 or MySQL 5.7, make them portable. So I download PostgreSQL server in zip, and extract it into D:\pgsql location, and I want run it portable-ly like I did with MySQL 8 and MySQL 5.7. But first, we need to initiate the PostgreSQL database system database, with this command in cmd.

> cd D:\pgsql\bin\
> pg_ctl -D D:\pgsql\data\ initdb -l logfile

Then after that we can run the PostgreSQL service with this command

> D:\pgsql\bin\pg_ctl -D D:\pgsql\data\ -l D:\pgsql\logfile start
waiting for server to start.... done
server started

Then the service will run as it’s. It’s quite simple. The question next is how to connect to the server, as we don’t have any credential when initiate the database? Well, it’s simple, check what is your user using this command

> whoami

Then the username is after the NetBios name, then try to connect using pgsql cli, try to run this command

> psql -l

                                            List of databases
   Name    | Owner | Encoding |          Collate          |           Ctype           | Access privileges
 postgres  | Ben   | WIN1252  | Indonesian_Indonesia.1252 | Indonesian_Indonesia.1252 |
 template0 | Ben   | WIN1252  | Indonesian_Indonesia.1252 | Indonesian_Indonesia.1252 | =c/Ben           +
           |       |          |                           |                           | Ben=CTc/Ben
 template1 | Ben   | WIN1252  | Indonesian_Indonesia.1252 | Indonesian_Indonesia.1252 | =c/Ben           +
           |       |          |                           |                           | Ben=CTc/Ben
(3 rows)

Then we can go try using our Database Client like Dbeaver, but it will cause errors (In some instance when we use Red Hat Java, so it’s broken), we can use some help with configuring the data/pg_hba.conf, and add some configuration line

# All Hosts
host    all             all                  trust 

just make sure that when you done this, it’s for your own dev box, in local network, on non production server!
I hope this post helpful for others that need it, and this is just notes for my own. If you felt there are wrong step, please do correct me. Thank you

Categorized as Blogs

By ben

I'm a geeks. Just look at my website :)

Leave a Reply. I will come back and maybe we can have some conversation :)

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: