diff --git a/src/node.py b/src/node.py
index c39f0ea..7dbe4fa 100644
--- a/src/node.py
+++ b/src/node.py
@@ -49,10 +49,7 @@
     HBA_CONF_FILE, \
     RECOVERY_CONF_FILE, \
     PG_LOG_FILE, \
-    UTILS_LOG_FILE, \
-    PG_CTL__STATUS__OK, \
-    PG_CTL__STATUS__NODE_IS_STOPPED, \
-    PG_CTL__STATUS__BAD_DATADIR \
+    UTILS_LOG_FILE
 
 from .consts import \
     MAX_LOGICAL_REPLICATION_WORKERS, \
@@ -349,136 +346,16 @@ def pid(self):
         Return postmaster's PID if node is running, else 0.
         """
 
-        self__data_dir = self.data_dir
+        x = self._get_node_state()
+        assert type(x) == utils.PostgresNodeState  # noqa: E721
 
-        _params = [
-            self._get_bin_path('pg_ctl'),
-            "-D", self__data_dir,
-            "status"
-        ]  # yapf: disable
-
-        status_code, out, error = execute_utility2(
-            self.os_ops,
-            _params,
-            self.utils_log_file,
-            verbose=True,
-            ignore_errors=True)
-
-        assert type(status_code) == int  # noqa: E721
-        assert type(out) == str  # noqa: E721
-        assert type(error) == str  # noqa: E721
-
-        # -----------------
-        if status_code == PG_CTL__STATUS__NODE_IS_STOPPED:
-            return 0
-
-        # -----------------
-        if status_code == PG_CTL__STATUS__BAD_DATADIR:
+        if x.pid is None:
+            assert x.node_status != NodeStatus.Running
             return 0
 
-        # -----------------
-        if status_code != PG_CTL__STATUS__OK:
-            errMsg = "Getting of a node status [data_dir is {0}] failed.".format(self__data_dir)
-
-            raise ExecUtilException(
-                message=errMsg,
-                command=_params,
-                exit_code=status_code,
-                out=out,
-                error=error,
-            )
-
-        # -----------------
-        assert status_code == PG_CTL__STATUS__OK
-
-        if out == "":
-            __class__._throw_error__pg_ctl_returns_an_empty_string(
-                _params
-            )
-
-        C_PID_PREFIX = "(PID: "
-
-        i = out.find(C_PID_PREFIX)
-
-        if i == -1:
-            __class__._throw_error__pg_ctl_returns_an_unexpected_string(
-                out,
-                _params
-            )
-
-        assert i > 0
-        assert i < len(out)
-        assert len(C_PID_PREFIX) <= len(out)
-        assert i <= len(out) - len(C_PID_PREFIX)
-
-        i += len(C_PID_PREFIX)
-        start_pid_s = i
-
-        while True:
-            if i == len(out):
-                __class__._throw_error__pg_ctl_returns_an_unexpected_string(
-                    out,
-                    _params
-                )
-
-            ch = out[i]
-
-            if ch == ")":
-                break
-
-            if ch.isdigit():
-                i += 1
-                continue
-
-            __class__._throw_error__pg_ctl_returns_an_unexpected_string(
-                out,
-                _params
-            )
-            assert False
-
-        if i == start_pid_s:
-            __class__._throw_error__pg_ctl_returns_an_unexpected_string(
-                out,
-                _params
-            )
-
-        # TODO: Let's verify a length of pid string.
-
-        pid = int(out[start_pid_s:i])
-
-        if pid == 0:
-            __class__._throw_error__pg_ctl_returns_a_zero_pid(
-                out,
-                _params
-            )
-
-        assert pid != 0
-        return pid
-
-    @staticmethod
-    def _throw_error__pg_ctl_returns_an_empty_string(_params):
-        errLines = []
-        errLines.append("Utility pg_ctl returns empty string.")
-        errLines.append("Command line is {0}".format(_params))
-        raise RuntimeError("\n".join(errLines))
-
-    @staticmethod
-    def _throw_error__pg_ctl_returns_an_unexpected_string(out, _params):
-        errLines = []
-        errLines.append("Utility pg_ctl returns an unexpected string:")
-        errLines.append(out)
-        errLines.append("------------")
-        errLines.append("Command line is {0}".format(_params))
-        raise RuntimeError("\n".join(errLines))
-
-    @staticmethod
-    def _throw_error__pg_ctl_returns_a_zero_pid(out, _params):
-        errLines = []
-        errLines.append("Utility pg_ctl returns a zero pid. Output string is:")
-        errLines.append(out)
-        errLines.append("------------")
-        errLines.append("Command line is {0}".format(_params))
-        raise RuntimeError("\n".join(errLines))
+        assert x.node_status == NodeStatus.Running
+        assert type(x.pid) == int  # noqa: E721
+        return x.pid
 
     @property
     def auxiliary_pids(self):
@@ -995,28 +872,17 @@ def status(self):
         Returns:
             An instance of :class:`.NodeStatus`.
         """
+        x = self._get_node_state()
+        assert type(x) == utils.PostgresNodeState  # noqa: E721
+        return x.node_status
 
-        try:
-            _params = [
-                self._get_bin_path('pg_ctl'),
-                "-D", self.data_dir,
-                "status"
-            ]  # yapf: disable
-            status_code, out, error = execute_utility2(self.os_ops, _params, self.utils_log_file, verbose=True)
-            if error and 'does not exist' in error:
-                return NodeStatus.Uninitialized
-            elif 'no server running' in out:
-                return NodeStatus.Stopped
-            return NodeStatus.Running
-
-        except ExecUtilException as e:
-            # Node is not running
-            if e.exit_code == 3:
-                return NodeStatus.Stopped
-
-            # Node has no file dir
-            elif e.exit_code == 4:
-                return NodeStatus.Uninitialized
+    def _get_node_state(self) -> utils.PostgresNodeState:
+        return utils.get_pg_node_state(
+            self._os_ops,
+            self.bin_dir,
+            self.data_dir,
+            self.utils_log_file
+        )
 
     def get_control_data(self):
         """
diff --git a/src/raise_error.py b/src/raise_error.py
new file mode 100644
index 0000000..62a3bbf
--- /dev/null
+++ b/src/raise_error.py
@@ -0,0 +1,27 @@
+
+
+class RaiseError:
+    @staticmethod
+    def pg_ctl_returns_an_empty_string(_params):
+        errLines = []
+        errLines.append("Utility pg_ctl returns an empty string.")
+        errLines.append("Command line is {0}".format(_params))
+        raise RuntimeError("\n".join(errLines))
+
+    @staticmethod
+    def pg_ctl_returns_an_unexpected_string(out, _params):
+        errLines = []
+        errLines.append("Utility pg_ctl returns an unexpected string:")
+        errLines.append(out)
+        errLines.append("------------")
+        errLines.append("Command line is {0}".format(_params))
+        raise RuntimeError("\n".join(errLines))
+
+    @staticmethod
+    def pg_ctl_returns_a_zero_pid(out, _params):
+        errLines = []
+        errLines.append("Utility pg_ctl returns a zero pid. Output string is:")
+        errLines.append(out)
+        errLines.append("------------")
+        errLines.append("Command line is {0}".format(_params))
+        raise RuntimeError("\n".join(errLines))
diff --git a/src/utils.py b/src/utils.py
index c04b4fd..f716152 100644
--- a/src/utils.py
+++ b/src/utils.py
@@ -10,11 +10,17 @@
 from contextlib import contextmanager
 from packaging.version import Version, InvalidVersion
 import re
+import typing
 
 from six import iteritems
 
 from .exceptions import ExecUtilException
 from .config import testgres_config as tconf
+from .raise_error import RaiseError
+from .enums import NodeStatus
+from .consts import PG_CTL__STATUS__OK
+from .consts import PG_CTL__STATUS__NODE_IS_STOPPED
+from .consts import PG_CTL__STATUS__BAD_DATADIR
 from testgres.operations.os_ops import OsOperations
 from testgres.operations.remote_ops import RemoteOperations
 from testgres.operations.local_ops import LocalOperations
@@ -315,3 +321,139 @@ def clean_on_error(node):
         # TODO: should we wrap this in try-block?
         node.cleanup()
         raise
+
+
+class PostgresNodeState:
+    node_status: NodeStatus
+    pid: typing.Optional[int]
+
+    def __init__(
+        self,
+        node_status: NodeStatus,
+        pid: typing.Optional[int]
+    ):
+        assert type(node_status) == NodeStatus  # noqa: E721
+        assert pid is None or type(pid) == int  # noqa: E721
+
+        self.node_status = node_status
+        self.pid = pid
+        return
+
+
+def get_pg_node_state(
+    os_ops: OsOperations,
+    bin_dir: str,
+    data_dir: str,
+    utils_log_file: typing.Optional[str],
+) -> PostgresNodeState:
+    assert isinstance(os_ops, OsOperations)
+    assert type(bin_dir) == str  # noqa: E721
+    assert type(data_dir) == str  # noqa: E721
+    assert utils_log_file is None or type(utils_log_file) == str  # noqa: E721
+
+    _params = [
+        os_ops.build_path(bin_dir, "pg_ctl"),
+        "-D",
+        data_dir,
+        "status",
+    ]
+
+    status_code, out, error = execute_utility2(
+        os_ops,
+        _params,
+        utils_log_file,
+        verbose=True,
+        ignore_errors=True,
+    )
+
+    assert type(status_code) == int  # noqa: E721
+    assert type(out) == str  # noqa: E721
+    assert type(error) == str  # noqa: E721
+
+    # -----------------
+    if status_code == PG_CTL__STATUS__NODE_IS_STOPPED:
+        return PostgresNodeState(NodeStatus.Stopped, None)
+
+    # -----------------
+    if status_code == PG_CTL__STATUS__BAD_DATADIR:
+        return PostgresNodeState(NodeStatus.Uninitialized, None)
+
+    # -----------------
+    if status_code != PG_CTL__STATUS__OK:
+        errMsg = "Getting of a node status [data_dir is {0}] failed.".format(
+            data_dir
+        )
+
+        raise ExecUtilException(
+            message=errMsg,
+            command=_params,
+            exit_code=status_code,
+            out=out,
+            error=error,
+        )
+
+    if out == "":
+        RaiseError.pg_ctl_returns_an_empty_string(
+            _params
+        )
+
+    C_PID_PREFIX = "(PID: "
+
+    i = out.find(C_PID_PREFIX)
+
+    if i == -1:
+        RaiseError.pg_ctl_returns_an_unexpected_string(
+            out,
+            _params
+        )
+
+    assert i > 0
+    assert i < len(out)
+    assert len(C_PID_PREFIX) <= len(out)
+    assert i <= len(out) - len(C_PID_PREFIX)
+
+    i += len(C_PID_PREFIX)
+    start_pid_s = i
+
+    while True:
+        if i == len(out):
+            RaiseError.pg_ctl_returns_an_unexpected_string(
+                out,
+                _params
+            )
+
+        ch = out[i]
+
+        if ch == ")":
+            break
+
+        if ch.isdigit():
+            i += 1
+            continue
+
+        RaiseError.pg_ctl_returns_an_unexpected_string(
+            out,
+            _params
+        )
+        assert False
+
+    if i == start_pid_s:
+        RaiseError.pg_ctl_returns_an_unexpected_string(
+            out,
+            _params
+        )
+
+    # TODO: Let's verify a length of pid string.
+
+    pid = int(out[start_pid_s:i])
+
+    if pid == 0:
+        RaiseError.pg_ctl_returns_a_zero_pid(
+            out,
+            _params
+        )
+
+    assert pid != 0
+
+    # -----------------
+    return PostgresNodeState(NodeStatus.Running, pid)
