We have a couple of template databases, and then we have the database, favoritecolors, that we just created. Just press Enter and you'll see a list of all the different databases that are on the current Postgres server. This isn't a SQL command, so you don't need a semi-colon at the end. To see a list of all the databases on the server, type backward slash, and then a lowercase letter l. When you press Enter, it returns CREATE DATABASE that tells me that the database was created successfully. We'll follow this with the name of the database that we want to create. We can do that with the CREATE DATABASE command. Okay, so we can run commands on the server and get back some information. That'll reveal the exact time and date that I'm recording this movie. You can type the semi-colon here on line number two and Postgres will then execute your statement when you press Enter. If you were to emit the semi-colon, Postgres doesn't know that you've finished with the command, and when you press Enter, it simply goes down to line number two. So once again, I'll say SELECT the function now, open and close parentheses and a closing semi-colon. Another command that we can send is to ask for the current date and time. I am working with Postgres version 12.2, and it was compiled by Visual C++ on Windows. When you press Enter, you should get a similar result. All these commands are going to finish with a semi-colon to tell the server that we're done typing and to go ahead and execute the statement. SELECT is a SQL command that returns information, and we're using a built-in function called version to pull out the server version and installation platform information. We can do that by running SELECT, version, and then an open and close parentheses. One thing that we can do is get details about the installation. Now we can start sending commands to the server. If everything was filled in correctly, you should be connected to the Postgres server and the command prompt will change. When you type, it's not going to appear on the screen, so just type it out and press Enter when you're done. So I hope that you remember what you filled in during that step. Again, we gave the Postgres user account a password during setup. If you've been assigned your own personal user account for your server, you would supply that username here instead. Again, during the installation, we created a superuser account named Postgres. Then we need to provide the user account credentials. This was set up during the installation step, but is typically left at the default of 5432. Next, we need the communication port that the server is listening on. Again, you can press Enter to accept the default value of Postgres. Our server is brand new and there's just one database called Postgres, so I'll log into that one. Each Postgres server can hold many different databases. Next, it asks you which database you want to connect to. I'll just leave this blank and press Enter to enter in localhost. You can either type that in or simply press Enter and localhost, the default as indicated by the text in square brackets, will be used instead. So we can use the word localhost instead. In our case, we're running the server and client on the same physical machine. If you're in a typical office environment where the Postgres server is running on a centralized computer, then you'll need the IP address of that machine. In order to log into a Postgres server, you need to know some connection details. When you first run the tool, it opens up a command-line window and starts the login process. So let's go ahead and click on it to start it up. And PSQL is a very important tool in the world of Postgres development. However, I do think that it's important to see briefly in order to help reinforce the idea that the client application is completely separate from the database server. It provides a quick way for administrators to log into the server and run commands, but it's not the most user-friendly environment for new users since it requires that you know what commands you want to run and how to type them out. The PSequel shell that we installed in the last movie is a command-line interface for working with Postgres database servers.
0 Comments
Leave a Reply. |