You just didn't finish your command.
Every "if" has to have a "fi"
That "mode" with the prompt ">" is telling you that you have not yet finished what you started.
service postgresql status; if [[ $? -eq 1 ]] ; then awk '{print ""$2""}' /root/file.txt ; fi
But you may have too many double quotes :
if service postgresql status ; then awk '{print "$2"}' /root/file.txt ; fi
Doing this over ssh will require different quoting because the local shell will process one
"layer" of quoting and the remote system will process the remaining one(s).
You have to make sure that the quotes and metacharacters that need to be seen by the remote shell
get all the way to the remote system.
Fortunately, the only thing going on here is the $2 that the remote awk needs.
I think this will work:
ssh hostname "if service postgresql status ; then awk '{print \$2}' /root/file.txt ; fi "