In general, questions in English must include one of the following:
- a helping (auxiliary) verb, such as have, will, and would,
- a form of the verb be,
- or a form of the verb do as an auxiliary verb, if neither of the above is present. In this case, the main verb is not modified by the subject or tense. "Does she drive?" is correct, while "Does she drives?" is not. "Did she drive?" is correct, not "Did she drove?"
In any past tense, the helping verbs are simply conjugated in the tense desired, such as did, were, was, had, etc.
Let's apply these rules to your examples.
How many pegs did you have?
This is correct, because it includes the helping verb do in past tense.
How many pegs did you drink?
Also correct, for the same reason as above.
How many pegs you drank?
This is incorrect; it does not have either a helping verb, a form of be, or a form of do. It is actually corrected by the sentence below it.
How many pegs have you drank?
This is correct, since the helping verb have is present, and drink is correctly put into the past participle form drank. This is how the sentence above it should read.
How many pegs you have had?
This is close, but the subject and verb should be inverted to form "How many pegs have you had?"