<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Chisaneme Aloni</title>
    <description>The latest articles on DEV Community by Chisaneme Aloni (@alachi24).</description>
    <link>https://dev.to/alachi24</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4274649%2Ff1e6b92c-9612-42d8-be5e-009896b95477.jpg</url>
      <title>DEV Community: Chisaneme Aloni</title>
      <link>https://dev.to/alachi24</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alachi24"/>
    <language>en</language>
    <item>
      <title>What MySQL Users Should Know Before Switching to PostgreSQL</title>
      <dc:creator>Chisaneme Aloni</dc:creator>
      <pubDate>Mon, 30 Nov 2026 22:42:00 +0000</pubDate>
      <link>https://dev.to/alachi24/what-mysql-users-should-know-before-switching-to-postgresql-2m61</link>
      <guid>https://dev.to/alachi24/what-mysql-users-should-know-before-switching-to-postgresql-2m61</guid>
      <description>&lt;p&gt;&lt;em&gt;Six things that surprised me while setting up PostgreSQL on Ubuntu&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I learnt MySQL in a coursework, and that is as far as my database experience goes. Then I installed PostgreSQL 18.6 on Ubuntu 26.04 (running under WSL2 on Windows) and wrote a setup guide for MySQL users while I did it. I must say, PostgreSQL surprised me more than once.&lt;/p&gt;

&lt;p&gt;This is what tripped me up, so I'm giving you a heads up. A note on sources: I ran every PostgreSQL command below on my own install. I did not run MySQL for this article, so where I describe MySQL's behavior, Just know I checked it against the official MySQL documentation.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. There is no &lt;code&gt;mysql -u root -p&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;In MySQL you log in as a named user with a password. On a fresh PostgreSQL install on Ubuntu, you do this instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo -u postgres psql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You run &lt;code&gt;psql&lt;/code&gt; as the Linux user called &lt;code&gt;postgres&lt;/code&gt;, and your prompt changes to &lt;code&gt;postgres=#&lt;/code&gt;. The &lt;code&gt;#&lt;/code&gt; means you are a superuser.&lt;/p&gt;

&lt;p&gt;To work as yourself, create a role that matches your Linux username, plus a database you own:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="no"&gt;ROLE&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;your&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="no"&gt;LOGIN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="n"&gt;practice&lt;/span&gt; &lt;span class="no"&gt;OWNER&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;your&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, from the normal terminal, run &lt;code&gt;psql -d practice&lt;/code&gt;. It lets you in without asking for a password, and your prompt ends in &lt;code&gt;&amp;gt;&lt;/code&gt; instead of &lt;code&gt;#&lt;/code&gt;, because you are a regular role.&lt;/p&gt;

&lt;p&gt;If you try this before creating the role, you get &lt;code&gt;FATAL:  role "&amp;lt;your-username&amp;gt;" does not exist&lt;/code&gt;. By default, &lt;code&gt;psql&lt;/code&gt; connects as a role with the same name as your Linux user.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. The same role needs a password in one place and none in another
&lt;/h2&gt;

&lt;p&gt;That password-free login is called &lt;strong&gt;peer authentication&lt;/strong&gt;. On a local Unix socket, PostgreSQL asks the operating system which Linux user is connecting, and trusts that name if a role with the same name exists.&lt;/p&gt;

&lt;p&gt;Now connect to the same database over TCP instead, using &lt;code&gt;-h 127.0.0.1&lt;/code&gt; (the &lt;code&gt;-w&lt;/code&gt; flag means never prompt for a password):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;psql -w -h 127.0.0.1 -d practice
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;psql: error: connection to server at "127.0.0.1", port 5432 failed: fe_sendauth: no password supplied
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same role, same database, different result. The rules live in a file called &lt;code&gt;pg_hba.conf&lt;/code&gt;, and PostgreSQL reads them top to bottom and uses the first match. Two of them explain what you just saw:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight conf"&gt;&lt;code&gt;&lt;span class="n"&gt;local&lt;/span&gt;   &lt;span class="n"&gt;all&lt;/span&gt;             &lt;span class="n"&gt;all&lt;/span&gt;                                     &lt;span class="n"&gt;peer&lt;/span&gt;
&lt;span class="n"&gt;host&lt;/span&gt;    &lt;span class="n"&gt;all&lt;/span&gt;             &lt;span class="n"&gt;all&lt;/span&gt;             &lt;span class="mf"&gt;127.0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;32&lt;/span&gt;            &lt;span class="n"&gt;scram&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;sha&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;256&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Over the socket (&lt;code&gt;local&lt;/code&gt;), the Linux username is enough. Over TCP (&lt;code&gt;host&lt;/code&gt;), a password is required. Applications, ORMs and GUI tools connect over TCP, so they need the password.&lt;/p&gt;

&lt;p&gt;This is different from MySQL, where access rules are stored as &lt;code&gt;'user'@'host'&lt;/code&gt; accounts and changed with SQL. In PostgreSQL, &lt;code&gt;pg_hba.conf&lt;/code&gt; decides who may connect and how, and &lt;code&gt;GRANT&lt;/code&gt; decides what they can do afterwards.&lt;/p&gt;

&lt;p&gt;One more trap: in MySQL, &lt;code&gt;-h localhost&lt;/code&gt; uses the socket. In PostgreSQL, &lt;code&gt;-h localhost&lt;/code&gt; uses TCP and asks for a password. To use the socket, leave out &lt;code&gt;-h&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Roles, not users
&lt;/h2&gt;

&lt;p&gt;PostgreSQL has roles. &lt;code&gt;CREATE USER&lt;/code&gt; is just shorthand for &lt;code&gt;CREATE ROLE ... WITH LOGIN&lt;/code&gt;, and a role without &lt;code&gt;LOGIN&lt;/code&gt; cannot connect at all.&lt;/p&gt;

&lt;p&gt;A role's name also does not include where it may connect from, which is what the &lt;code&gt;@'host'&lt;/code&gt; part does in MySQL. That is &lt;code&gt;pg_hba.conf&lt;/code&gt;'s job.&lt;/p&gt;

&lt;p&gt;Set the password privately instead of typing it inside the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;\&lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;your&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;PostgreSQL asks you to type it twice, and nothing shows on screen as you type.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Commands that start with a backslash
&lt;/h2&gt;

&lt;p&gt;Inside &lt;code&gt;psql&lt;/code&gt;, many everyday tasks are backslash shortcuts, not SQL:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;\l&lt;/code&gt; lists databases (MySQL: &lt;code&gt;SHOW DATABASES;&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;\dt&lt;/code&gt; lists tables (&lt;code&gt;SHOW TABLES;&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;\d notes&lt;/code&gt; describes a table (&lt;code&gt;DESCRIBE notes;&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;\du&lt;/code&gt; lists roles&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;\q&lt;/code&gt; quits (&lt;code&gt;exit&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These take no semicolon. SQL statements do. If you forget one, &lt;code&gt;psql&lt;/code&gt; does not complain. It waits for more input, and the last-but-one character of the prompt changes from &lt;code&gt;=&lt;/code&gt; to &lt;code&gt;-&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;postgres=&amp;gt; SELECT current_user
postgres-&amp;gt; ;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Type &lt;code&gt;;&lt;/code&gt; to run it, or &lt;code&gt;\r&lt;/code&gt; to clear what you typed.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Identity columns say no
&lt;/h2&gt;

&lt;p&gt;MySQL's &lt;code&gt;AUTO_INCREMENT&lt;/code&gt; has a modern PostgreSQL equivalent:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;notes&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="kt"&gt;INT&lt;/span&gt; &lt;span class="no"&gt;GENERATED&lt;/span&gt; &lt;span class="no"&gt;ALWAYS&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="no"&gt;IDENTITY&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="kt"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="kt"&gt;TIMESTAMPTZ&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="nb"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then try to insert your own ID:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;notes&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'manual id'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ERROR:  cannot insert a non-DEFAULT value into column "id"
DETAIL:  Column "id" is an identity column defined as GENERATED ALWAYS.
HINT:  Use OVERRIDING SYSTEM VALUE to override.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;PostgreSQL refuses. According to the MySQL docs, &lt;code&gt;AUTO_INCREMENT&lt;/code&gt; accepts a manual value and continues the sequence from the largest one. If you want PostgreSQL to behave more like MySQL, define the column as &lt;code&gt;GENERATED BY DEFAULT AS IDENTITY&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. "active (exited)" is not a crash
&lt;/h2&gt;

&lt;p&gt;When I checked the service, I saw this and was like, where's my mistake now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Active: active (exited) since Mon 2026-11-16 01:44:04 WAT
Process: 403 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It had not. On Ubuntu, &lt;code&gt;postgresql.service&lt;/code&gt; is only a wrapper that runs &lt;code&gt;/bin/true&lt;/code&gt; and exits, so it always says &lt;code&gt;active (exited)&lt;/code&gt;. The real server runs as a separate unit for each cluster. To check it properly, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pg_lsclusters
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ver Cluster Port Status Owner    Data directory              Log file
18  main    5432 online postgres /var/lib/postgresql/18/main /var/log/postgresql/postgresql-18-main.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A status of &lt;code&gt;online&lt;/code&gt; means the server is running.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would tell another MySQL user
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Login depends on how you connect: socket or TCP.&lt;/li&gt;
&lt;li&gt;Think in roles, and remember that &lt;code&gt;pg_hba.conf&lt;/code&gt; decides who gets in.&lt;/li&gt;
&lt;li&gt;Learn the backslash commands, and end SQL statements with a semicolon.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The full guide, with every command, its real output and a troubleshooting table, is on GitHub: &lt;a href="https://github.com/Alachi24/postgresql-for-mysql-users" rel="noopener noreferrer"&gt;https://github.com/Alachi24/postgresql-for-mysql-users&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you find a mistake, open an issue on the repository. I would rather fix it than leave it.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>postgres</category>
      <category>mysql</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
