17

Two days ago, i started learning postgresql. Most tutorials I followed online were either old or the codes wont just work on my mac. I followed a lot of tutorials that did a lot of totally different things. When i switched on my system today. I noticed Postgresql created a user on my mac. I don't know what this is or maybe i used the wrong CLI code.

enter image description here

When I tried viewing the user, I saw this

enter image description here

should I delete this user or it has a function?

9
  • How did you install Postgres? I didn't have this happen when installing via Homebrew, which Postgres recommends. Commented Feb 23, 2019 at 19:15
  • I installed via homebrew. also installed homebrew too. Just wondering if i entered the wrong CLI code Commented Feb 23, 2019 at 19:33
  • Hard to say. What CLI code did you enter? brew install postgres shouldn't've caused this, I don't think. Commented Feb 23, 2019 at 19:46
  • This Question might have been better asked on the sister site, dba.stackexchange.com Commented Feb 23, 2019 at 20:33
  • @Basil Thanks, would do that. Commented Feb 23, 2019 at 22:15

2 Answers 2

20

postgres user account

Creating a user account specifically for Postgres, commonly named postgres, is a normal part of a Postgres installation. Your installer app likely prompted you for a password to assign to this new user account.

One reason for this is security: The database’s data files and security configuration files are stored in folders owned by the postgres user. So if your main user account is hijacked, the intruder does not yet have access to the database (often the most valuable thing in storage). The intruder must jump through more hoops to compromise Postgres. Also, the separate ownership prevents other apps from inadvertently stomping on the Postgres files.

You will find Postgres is much more enterprise-oriented than other products such as MySQL. This means locking-down for security. Another example: Postgres by default is configured to not accept connections over the network. To enable connections from other computers, you must change the configuration. Inconvenient for the beginner, but more secure. Like a bar on your car steering wheel and deadbolts on your doors, more security always means more steps to take and more annoyance.

Use a virtual machine

Installing the postgres user account is one of the things that makes Postgres a rather heavyweight installation. I suggest to those learning Postgres to use a virtual machine for Postgres. Something like:

To remove Postgres, simply discard the vm.

Postgres.app for macOS

Another option for a Mac user is Postgres.app, created by the person who built one of the first Postgres-as-a-Service implementations (on Heroku). I have not used Postgres.app, but I understand it wraps Postgres, so it does not install the postgres user account. Also, Postgres starts and stops when launch and quit the app, rather than running in the background all the time.

Be aware: you may have conflicts with Postgres.app on a Mac where you already have a conventional installation. I suggest you first carefully remove the conventional Postgres from your Mac before installing Postgres.app. Uninstalling involves finding and deleting various files and folders in various places.

Database-as-a-Service (DBaaS)

Another option to avoid local installation is the increasing choices for running Postgres as a service. This is sometimes referred to as “managed Postgres” because the vendor maintains the installation of Postgres on your behalf. You simply use Postgres to create your database, but you do not fully control Postgres in such a service.

Some examples:

Podman container

Another option is using a Podman container, in either their console (command-line) app or their desktop (GUI) app.

On a Mac, this tool has a virtual machine to run Linux. You can then layer over additional software such as a pre-configured Postgres installation.

This approach is very fast and convenient as you do not have to sit through the actual installation process of either Linux nor Postgres. The software is all “pre-baked” for your convenience.

Your Postgres user account(s) will exist within this virtualized Linux OS, isolated from your host macOS.

This Podman approach to accessing Postgres is especially attractive if you want to either (a) install other software alongside Postgres, and/or (b) wipe and install again fresh. Layering software in a container is very fast, convenient, and repeatable.

Docker

Or you can use Docker. Same idea as Podman. But due to technical architecture differences, Podman is more secure than Docker. And there may be legal differences in licensing terms.

Podman is a superset of Docker. If familiar with Docker, your skills apply to Podman as well.

My experience

Personally, I used to install Postgres on a Mac using the installer by EnterpriseDB.com. That company sells added-value versions of Postgres, but kindly provides an installer for plain-vanilla Postgres, as a service to the community.

I have also used that same installer from EnterpriseDB.com to install onto a Parallels VM running macOS as the guest OS within the VM on a MacBook Pro running macOS as the host OS. You can easily configure the VM to share the host Mac’s IP address on the network, or you can give the VM its own network address which might be handy for demo/dev/test work.

Thirdly, I have installed Postgres on FreeBSD on DigitalOcean.com.

All three of these options have worked quite well for me. Which is preferable depends on the scenario. For example, the DigitalOcean.com approach is good if I want colleagues to be able to reach the database 24x7 without my own MacBook being available.

This discussion is for development work. For mission-critical deployment, I strongly recommend using heavy-duty server equipment with error-correcting memory and redundant storage such as RAID or ZFS pool. Postgres is extremely reliable but depends, of course, on reliable hardware.


Your tag says Postgres 9.1. That version is quite old now. I suggest using the latest version. By the way, the version numbering system has changed for postgres. The first number is now the roughly-annual release number likely requiring you to dump and reload data to upgrade, and the second number is compatible updates.

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks a lot for explaining this!!. But i already deleted this acct! What can i do?
@Pelumi Is this macOS? You might be able to recreate the account with the same name. Hopefully that would give the new user access to the existing Postgres-related files and folders. Or, you could follow the link I provided, to search for details on how to delete Postgres from your Mac. This is likely to be: (1) Run an uninstall-script left by your installer. (2) Manually deleting a few leftover files and folders in various nooks-and-crannies. Then you can re-install Postgres if desired, or use one of the alternatives I suggested. Sorry for your hassles, but Postgres is worth it (awesome db)!
@Pelumi So your added new user account with the same name postgres was given access by macOS to the existing Postgres-related folders and files? Please confirm or explain -- interesting to know.
I'm not so sure if it has access to the Postgres related files. I'm new to database. Everything still kind of sounds weird to me. But i added the account back manually. How do i know if it has access to them?
@Pelumi Either your Postgres works or it doesn't -- that will tell you. I suspect you be better off removing Postgres entirely as instructed in steps 1 & 2 of my comment above, and staring from scratch, but that is just a guess.
|
8

As pointed out by @basil-bourque, the account is required for several reasons. That said, if it annoys you to have the PostgreSQL showing up in the login screen -as it did me-, you can remove it as long as you have admin user rights in MacOS.

Apple Support gives the following command to hide a user from the login screen:

$ sudo dscl . create /Users/hiddenuser IsHidden 1

However, since the PostgreSQL user was not included listed in the login window at installation, that command will yield no result -at least in Catalina, which is my OS. You should use the following two commands instead, as suggested by josemarluedke:

## add postgres to the list of hidden users on login screen
$ sudo defaults write /Library/Preferences/com.apple.loginwindow HiddenUsersList -array-add 'postgres'
## instruct not to show any hidden accounts at login
$ sudo defaults write /Library/Preferences/com.apple.loginwindow SHOWOTHERUSERS_MANAGED -bool FALSE

Worked for me!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.