Again, during the installation, we created a superuser account named Postgres. If you've been assigned your own personal user account for your server, you would supply that username here instead. Again, we gave the Postgres user account a password during setup. So I hope that you remember what you filled in during that step. When you type, it's not going to appear on the screen, so just type it out and press Enter when you're done. If everything was filled in correctly, you should be connected to the Postgres server and the command prompt will change. Now we can start sending commands to the server. One thing that we can do is get details about the installation. ![]() We can do that by running SELECT, version, and then an open and close parentheses. 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. 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. When you press Enter, you should get a similar result. I am working with Postgres version 12.2, and it was compiled by Visual C++ on Windows. Another command that we can send is to ask for the current date and time. So once again, I'll say SELECT the function now, open and close parentheses and a closing semi-colon. 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. You can type the semi-colon here on line number two and Postgres will then execute your statement when you press Enter. That'll reveal the exact time and date that I'm recording this movie. Okay, so we can run commands on the server and get back some information. We can do that with the CREATE DATABASE command. We'll follow this with the name of the database that we want to create. When you press Enter, it returns CREATE DATABASE that tells me that the database was created successfully. To see a list of all the databases on the server, type backward slash, and then a lowercase letter l. ![]() This isn't a SQL command, so you don't need a semi-colon at the end. Just press Enter and you'll see a list of all the different databases that are on the current Postgres server. We have a couple of template databases, and then we have the database, favoritecolors, that we just created. In order to work with the favoritecolors database, we need to switch into it. ![]() Remember that when we logged into the server, we logged into the Postgres database.
0 Comments
Leave a Reply. |