![]() ![]() Now that postgres is installed the default server can be started by running the command: This can be done by typing the following command into a terminal: Homebrew is a powerful package manager with many uses, including installing and running postgreSQL. This will start up a postgres server hosted locally on port 5432. It can now be accessed by typing the following command: The server will be run out of the directory /usr/local/var/postgres. This will connect to the server and access the postgres database. Data can be loaded and deleted from the database.This shows that the server has been started and can be connected to. (Optional) Creating a Custom Data DirectoryĪ custom data directory can also be used for a server. For example, create a directory called myData in the home directory: To do this, first create a directory to be used as the server location. Once the directory is created, the server can be initialized. This will fill the myData directory with files necessary to run the server: To do this run the initdb command as shown: This means that we configure the directory and add the necessary files to run the server. To do this use the command and substitute in for the specified values: Now that the server is initialized and the log file is created, you can start the server from this directory. The 'Data Directory' refers to the directory that was just initialized (in this case myData). The 'Log file' is a file that will record server events for later analysis. Generally log files are formatted to contain the date in the file name (e.g. Log files can be dense to read but are very useful for security and debugging purposes: '.log' or 'myData-logfile-.log') and should be stored outside of the database that they are logging so as to avoid unnecessary risks. If a log file is not specified, events will be logged to the terminal: The command above will generate a log file like the one shown, start the server, and tie the log file to the server. ![]() ![]() The server will only start if the port is free. Once started, it can be connected to the same way as before using: Using PostgreSQL App If the default server is running it must first be stopped using the pg_ctl -D /usr/local/var/postgres stop command: To run a server through the postgres app, the first step is to download the program. Once the app is downloaded and moved into the applications folder, the app can be opened. Details on the server can be found by opening the server settings: In order to start the server, click the start button. This interface shows all the essential information regarding the server. This is useful because multiple PostgreSQL servers can It also allows the port to be changed very easily. This looks like the following: Using Terminal with the PostgreSQL App Note: To change the port in the terminal, the ‘nf' file (which can be found in the data directory) must be edited. These tools can be accessed by typing:įor example, the ‘postgres' database on the server can be connected to using the psql tool with postgres as an argument: Once the app has been downloaded, command line tools can be used as well. Rather than typing out the full path each time however, the path can be added to a file that will allow significantly easier access to the tools, allowing the tools be accessed from any directory on the computer. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |