The owner of the table will be the user executing the command. The CREATE TABLE statement creates a new table in the current database. You can use \d command to view tables in a database.Ĭurrently, there are no tables in the database “henry”. It is useful for storing structured data such as customers, products, employees, etc. Step 7: Create Tables in the DatabaseĪ relational database can contain multiple related tables. \conninfoĪs you can see, it shows that you are now connected to the database henry as user henry this time. Then type this command to check connection details. Run the psql command to open Postgres shell as user “henry”. sudo adduser henryĪfter creating the user, switch to the user henry using the following command. So, if you do not have a matching user with the same name, you have to create one first. Step 6: Open Postgres Shell with the New RoleĪ system account with the same username as the role is able to log in to that role. Run the \l command to check if the new database is created. This command creates a new database “henry”. You can create a new database using the createdb command. So, if you created a new database henry, the role henry will connect to it by default. Now, let’s create a new database for the user “henry”.īy default, the role used to log in has a database with the same name that it can access in PostgreSQL. You have successfully created a new role “henry” on the server. createuser -interactiveĪfter entering the value, launch the interactive shell and run \du command to verify the new role.Īs you can see, the role henry is created and has superuser attributes. The -interactive flag will prompt you to enter the new role’s name and ask if it should have superuser privileges. You can create a new role using the createuser command. Multiple roles will provide you the flexibility of managing databases as different users. It will set the password “admin123” for the postgres user. ALTER USER postgres WITH PASSWORD 'admin123' For this, you have to run the below command at the prompt. The postgres user does not have any password, you have to set it yourself. It has superuser permissions and can create new roles and databases on the server. \duĪs you can see, there is only one role “postgres” which is the default role created during the installation process. You can view a list of roles in PostgreSQL using the \du command. To exit the interactive interface, run the \q command. You can view a list of all databases by using the \l command. The postgres user automatically connects to the database postgres when you run the psql command.Īt the prompt, type the \conninfo command to check the details of the connection. Similarly, PostgreSQL also creates a default database postgres during installation. For example, this single command will launch an interactive Postgres shell as a postgres user. You can also open the Postgres shell without switching accounts. Then enter the following command to open the interactive Postgres shell. You have to log on to that account to connect and access the working shell of the PostgreSQL server. The output will be similar as shown in the image below.īy default, PostgreSQL creates a user account postgres during the installation process. You can verify it using the following command. sudo apt install postgresql postgresql-contrib Step 2: Check the PostgreSQL serviceĪfter completing the installation, the PostgreSQL service should be active by default. Next, run this command to install the latest version of PostgreSQL along with a contrib package that provides additional tools and functionalities for PostgreSQL. It helps to get information about updated packages and their dependencies. Step 1: Install PostgreSQL on Ubuntuīefore getting started, update your package information using the below command. The following step-by-step guide uses Ubuntu 20.04 system to demonstrate the installation and configuration of PostgreSQL on Ubuntu. Prerequisitesįor this tutorial, you will need a Ubuntu system having a non-root user with sudo privileges. This tutorial will teach you how to install and set up PostgreSQL on the Ubuntu system. It is compatible with all major operating systems including Windows, Linux/UNIX, Mac OS, IRIX, Solaris, etc. It allows you to create your own data types, define custom functions, and write different programming language codes without recompiling your database. With over 30 years of active development, it has gained a solid reputation for its reliability, data integrity, extensibility, ACID compliance, and robust features. PostgreSQL is a free and open-source relational database management system that allows both SQL and JSON querying.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |