0

I've been having a bit of trouble trying to install PostgreSQL 14 for the first time.

I would like to apologize in advance if this question has been asked in the manner that I am about to ask it, but I do not think it has. If it has been, please direct me to the appropriate location!

I've done a fair amount of Googling on the matter, and all the information that I find seems to be rather fragmented, or I end up following a spaghetti trail of hyperlinks (a la-do-this-and-follow-this-other-link-with-more-information-than-you-need-to-understand-this-other-required-portion). Personally, I don't want to jump around to 50 different locations on the web to try and conjure up a piecemeal solution that I believe works, only to be proven wrong later. I want to know what to do and why it works. I've tried reading the documentation, and have given up on it, because to me, it seems to assume that the server has already been set up by a database administrator.

Instead of articulating my problem directly (as I seem to be having more trouble than I would like by trying to do so), I believe it would be easier to articulate my problem indirectly by stating what my expectations would be after installing PostgreSQL for the first time.

So to start, I will mention that I'm running Ubuntu 18.04.6 LTS, and am installing PostgreSQL 14.1 with the following command:

sudo apt install postgresql-14

Before continuing, I would like to add a side note in advance, that I do not want suggestions for an alternative OS or install method. I just want to be able to get "up and running" in a common-sense fashion from this exact point.

Moving on, I know that the aforementioned command creates a *nix user called postgres.

From here, I can now indirectly state my problem using an outline of what my goals and expectations are immediately after installing the software via that command.

  • After installing PostgreSQL via apt, these are my expected goals:
    • I want any client to be able to connect to the database server from any computer where a route exists from the client to the server.
      • For the sake of simplicity with these stated goals, when it is directly or implicitly stated that I am trying to connect a client to the database server, I am making the assumption that the client is able to, at a minimum, ping the machine that the server is running on, and vice versa.
      • For now, I'm not completely worried about the database being accessible from the public Internet.
      • I expect to be able to access the database from any computer on my LAN, whether it is an actual LAN, or some sort of logical LAN (like a WAN or a VPN).
    • If I change the PostgreSQL password of the postgres user, I expect that any client logging into the database  server via the postgres user will require the password.
      • This means if I want to change the password to some_password via \password postgres or ALTER USER postgres WITH PASSWORD 'some_password'; (I am assuming this is how you change the login password of a PostgreSQL user), then...
        • I expect running psql [-h host] -U postgres -W from any host...
          • That when I am prompted to enter the password... 
            • I can only log in by entering the exact password of some_password.
            • Entering any other arbitrary text for the password should not allow me to log in.
              • I am adding this as a requirement because previous install attempts have shown me that this is NOT the case.
      • I expect to be able to create a PostgreSQL user account other than postgres (e.g. db_user) with a password and have it be subject to the same requirements as the postgres user.
        • i.e. once the new account is given permission to log in, the same common-sense login requirements to log in must be imposed, i.e. you can't get in if you don't have the correct username/password combination. 

If the process to achieve the aforementioned can be explained in such a way that it can be understood with minimal mental friction, I would be extremely grateful.

Feel free to assume that my knowledge is on par with that of a undergraduate CS student who just completed their first year of university, who also understands Linux filesystems and basic computer networking. I just want the answer to be as accessible to as many people as possible, as I am sure I'm not the only person who has struggled with installing PostgreSQL, in spite of having a power user's level of computer literacy.

4

1 回答 1

1
  1. sudo apt install postgresql

  2. sudo -u postgres psql

    • 使用 \password 或您提到的其他方法为该用户设置密码
  3. 须藤 vi /etc/postgresql/10/main/pg_hba.conf

    • 将此文件中唯一未注释的非空行设为host all all all md5
  4. 须藤 vi /etc/postgresql/10/main/postgresql.conf

    • 取消注释 listen_addresses 行并将其设置为 '*'
  5. sudo service postgresql 重启

当您创建一个新用户时,您还应该创建一个与该用户具有相同拼写的新数据库。否则,当您尝试使用 psql -U 登录时,您将需要指定数据库名称,例如psql -U newname -d postgres -h[hhh]. 如果您实际上运行的是 14 而不是 10,那么您将需要更改需要相应编辑的配置文件的路径。

于 2021-12-15T02:48:11.563 回答